Sorry - I don't think I was very clear in my email.  Try this:

import pylab as p
p.plot( [] ()
p.gca().xaxis_date()
p.show()

While this is a silly example, we do a lot of embedding of plots in GUI's
and this does come up. Normal MPL mode is something like:

- get data
- plot data
- configure and format plot

But in an embedded GUI, it's much easier to write code like this:

- configure and format plot
- wait for data
- get data and plot

So we want to be able to create a plot widget and set all the options and
formatting we want to use on it.  Then wait for data to arrive or be input
and plot it.  The problem is that it turns out there are a lot of places
where autoscaling or other algorithms cause date formatting to fail w/ a
similar message about not being able to handle zero or negative numbers.
You can work around them if you know they're going to show up but it's
frustrating.  It would be nice if date formatting could be applied to any
plot range and have it work.

I'll make some more concrete examples later - I think it's something we can
fix.  I'd like to get a suite of examples that illustrate some of the
problems before I/we start thinking about possible solutions.

Ted


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> John Hunter
> Sent: Tuesday, June 03, 2008 1:51 PM
> To: Ted Drain
> Cc: Matplotlib
> Subject: Re: [matplotlib-devel] date2num/num2date and ordinal date
> 
> On Tue, Jun 3, 2008 at 3:41 PM, Ted Drain <[EMAIL PROTECTED]>
> wrote:
> 
> > At some point in the future, I'll put a little test case together to
> show
> > how the problems w/ not supporting a zero date show up in embedded
> plots.
> 
> Actually, when you pass in python datetime objects to mpl, we use the
> units converter infrastructure to convert these under the hood using
> date2num.   This is fairly easy to override in the units registry.  If
> you provide a registry to do conversions, locators and formatters for
> julian dates, I can easily include it with an rc setting to make a
> configurable default.
> 
> The date interface is setup in the matplotlib.dates module with the
> following code -- all you have to do is provide a different converter
> and we can provide a hook
> 
>     class DateConverter(units.ConversionInterface):
> 
>         def axisinfo(unit):
>             'return the unit AxisInfo'
>             if unit=='date':
>                 majloc = AutoDateLocator()
>                 majfmt = AutoDateFormatter(majloc)
>                 return units.AxisInfo(
>                     majloc = majloc,
>                     majfmt = majfmt,
>                     label='',
>                     )
>             else: return None
>         axisinfo = staticmethod(axisinfo)
> 
>         def convert(value, unit):
>             if units.ConversionInterface.is_numlike(value): return
> value
>             return date2num(value)
>         convert = staticmethod(convert)
> 
>         def default_units(x):
>             'return the default unit for x or None'
>             return 'date'
>         default_units = staticmethod(default_units)
> 
> 
>     units.registry[datetime.date] = DateConverter()
>     units.registry[datetime.datetime] = DateConverter()
> 
> -----------------------------------------------------------------------
> --
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to