On Tue, Apr 14, 2009 at 8:34 AM, Ryan May <rma...@gmail.com> wrote:

> I don't think matplotlib supports anything like this out of the box.
> However, you should be able to do this by subclassing the Formatter class in
> matplotlib/ticker.py.  I believe Chaco has support for ticking like this for
> dates, so you could look to it for inspiration on how to go about
> implementing the concept.

Here is the code for the autodateformatter (scale is in days).
Perhaps you can just tweak it to work like you want and then set you
custom formatter with

  ax.xaxis.set_major_formatter(myformatter)


   class AutoDateFormatter(ticker.Formatter):
       """
       This class attempts to figure out the best format to use.  This is
       most useful when used with the :class:`AutoDateLocator`.
       """

       # This can be improved by providing some user-level direction on
       # how to choose the best format (precedence, etc...)

       # Perhaps a 'struct' that has a field for each time-type where a
       # zero would indicate "don't show" and a number would indicate
       # "show" with some sort of priority.  Same priorities could mean
       # show all with the same priority.

       # Or more simply, perhaps just a format string for each
       # possibility...

       def __init__(self, locator, tz=None):
           self._locator = locator
              self._formatter = DateFormatter("%b %d %Y %H:%M:%S %Z", tz)
              self._tz = tz

          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)

           return self._formatter(x, pos)


JDH

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to