From: <jd...@us...> - 2009-08-20 23:11:53
|
Revision: 7511 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7511&view=rev Author: jdh2358 Date: 2009-08-20 23:11:44 +0000 (Thu, 20 Aug 2009) Log Message: ----------- make autodateformatter customizable Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py trunk/matplotlib/lib/matplotlib/dates.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-08-20 16:19:22 UTC (rev 7510) +++ trunk/matplotlib/CHANGELOG 2009-08-20 23:11:44 UTC (rev 7511) @@ -1,3 +1,6 @@ +2009-08-20 Added scaled dict to AutoDateFormatter for customized + scales - JDH + 2009-08-15 Pyplot interface: the current image is now tracked at the figure and axes level, addressing tracker item 1656374. - EF Modified: trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py 2009-08-20 16:19:22 UTC (rev 7510) +++ trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py 2009-08-20 23:11:44 UTC (rev 7511) @@ -136,5 +136,6 @@ ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) + fig.savefig('ribbon_box.png') plt.show() Modified: trunk/matplotlib/lib/matplotlib/dates.py =================================================================== --- trunk/matplotlib/lib/matplotlib/dates.py 2009-08-20 16:19:22 UTC (rev 7510) +++ trunk/matplotlib/lib/matplotlib/dates.py 2009-08-20 23:11:44 UTC (rev 7511) @@ -378,6 +378,28 @@ """ This class attempts to figure out the best format to use. This is most useful when used with the :class:`AutoDateLocator`. + + + The AutoDateFormatter has a scale dictionary that maps the scale + of the tick (the distance in days between one major tick) and a + format string. The default looks like this:: + + self.scaled = { + 365.0 : '%Y', + 30. : '%b %Y', + 1.0 : '%b %d %Y', + 1./24. : '%H:%M:%D', + } + + + The algorithm picks the key in the dictionary that is >= the + current scale and uses that format string. You can customize this + dictionary by doing:: + + + formatter = AutoDateFormatter() + formatter.scaled[1/(24.*60.)] = '%M:%S' # only show min and sec + """ # This can be improved by providing some user-level direction on @@ -392,28 +414,29 @@ # possibility... def __init__(self, locator, tz=None): + """ + """ self._locator = locator - self._formatter = DateFormatter("%b %d %Y %H:%M:%S %Z", tz) self._tz = tz + self._formatter = DateFormatter("%b %d %Y %H:%M:%D", tz) + self.scaled = { + 365.0 : '%Y', + 30. : '%b %Y', + 1.0 : '%b %d %Y', + 1./24. : '%H:%M:%S', + } def __call__(self, x, pos=0): scale = float( self._locator._get_unit() ) - if ( scale == 365.0 ): - self._formatter = DateFormatter("%Y", self._tz) - elif ( scale == 30.0 ): - self._formatter = DateFormatter("%b %Y", self._tz) - elif ( (scale == 1.0) or (scale == 7.0) ): - self._formatter = DateFormatter("%b %d %Y", self._tz) - elif ( scale == (1.0/24.0) ): - self._formatter = DateFormatter("%H:%M:%S %Z", self._tz) - elif ( scale == (1.0/(24*60)) ): - self._formatter = DateFormatter("%H:%M:%S %Z", self._tz) - elif ( scale == (1.0/(24*3600)) ): - self._formatter = DateFormatter("%H:%M:%S %Z", self._tz) - else: - self._formatter = DateFormatter("%b %d %Y %H:%M:%S %Z", self._tz) + keys = self.scaled.keys() + keys.sort() + for k in keys: + if k>=scale: + self._formatter = DateFormatter(self.scaled[k]) + break + return self._formatter(x, pos) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |