[Scipy-svn] r3041 - trunk/Lib/sandbox/timeseries/plotlib

scipy-svn at scipy.org scipy-svn at scipy.org
Fri May 25 11:27:43 EDT 2007


Author: mattknox_ca
Date: 2007-05-25 10:27:39 -0500 (Fri, 25 May 2007)
New Revision: 3041

Modified:
   trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py
Log:
added additional frequency support for plots. All frequencies <= daily are now supported (eg. the various annual and quarterly frequencies, weekly, etc)

Modified: trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py
===================================================================
--- trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py	2007-05-24 17:11:57 UTC (rev 3040)
+++ trunk/Lib/sandbox/timeseries/plotlib/mpl_timeseries.py	2007-05-25 15:27:39 UTC (rev 3041)
@@ -175,8 +175,13 @@
 
     if freq == _c.FR_BUS:
         periodsperyear = 261
+        periodspermonth = 19
     elif freq == _c.FR_DAY:
         periodsperyear = 365
+        periodspermonth = 28
+    elif TS.get_freq_group(freq) == _c.FR_WK:
+        periodsperyear = 52
+        periodspermonth = 3
     else:
         raise ValueError("unexpected frequency")
 
@@ -195,7 +200,7 @@
         else: return label_flags[0]
 
     # Case 1. Less than a month
-    if span <= (periodsperyear//12 - 2):
+    if span <= periodspermonth:
         month_start = period_break(dates,'month')
         if aslocator:
             major = default[month_start]
@@ -377,7 +382,7 @@
         return dict([(d,f) for (d,f) in zip(dates[formatted],format[formatted])])
 #...............................................................................
 def _quarterly_finder(vmin, vmax, freq, aslocator):
-    if freq != _c.FR_QTR:
+    if TS.get_freq_group(freq) != _c.FR_QTR:
         raise ValueError("unexpected frequency")
     periodsperyear = 4
     (vmin, vmax) = (int(vmin), int(vmax))
@@ -394,20 +399,20 @@
             minor = dates
         else:
             format[:] = 'Q%q'
-            format[year_start] = 'Q%q\n%Y'
+            format[year_start] = 'Q%q\n%F'
             if not has_level_label(year_start):
                 if dates.size > 1:
                     idx = 1
                 else:
                     idx = 0
-                format[idx] = 'Q%q\n%Y'
+                format[idx] = 'Q%q\n%F'
     #............................................
     elif span <= 11 * periodsperyear:
         if aslocator:
             major = dates[year_start]
             minor = dates
         else:
-            format[year_start] = '%Y'
+            format[year_start] = '%F'
     #............................................
     else:
         years = dates[year_start]//4 + 1
@@ -418,7 +423,7 @@
             major = dates[major_idx]
             minor = dates[year_start[(years % min_anndef == 0)]]
         else:
-            format[major_idx] = '%Y'
+            format[major_idx] = '%F'
     #............................................
     if aslocator:
         return minor, major
@@ -466,11 +471,11 @@
         #.....
         if fgroup == _c.FR_ANN:
             self.finder = _annual_finder
-        elif freq == _c.FR_QTR:
+        elif fgroup == _c.FR_QTR:
             self.finder = _quarterly_finder
         elif freq == _c.FR_MTH:
             self.finder = _monthly_finder
-        elif freq in (_c.FR_BUS, _c.FR_DAY):
+        elif freq in (_c.FR_BUS, _c.FR_DAY) or fgroup == _c.FR_WK:
             self.finder = _daily_finder
 
     def asminor(self):
@@ -536,11 +541,11 @@
         #.....
         if fgroup == _c.FR_ANN:
             self.finder = _annual_finder
-        elif freq == _c.FR_QTR:
+        elif fgroup == _c.FR_QTR:
             self.finder = _quarterly_finder
         elif freq == _c.FR_MTH:
             self.finder = _monthly_finder
-        elif freq in (_c.FR_BUS, _c.FR_DAY):
+        elif freq in (_c.FR_BUS, _c.FR_DAY) or fgroup == _c.FR_WK:
             self.finder = _daily_finder
 
     def asminor(self):




More information about the Scipy-svn mailing list