On Mon, Aug 29, 2011 at 2:56 PM, Mark Bakker <mark...@gmail.com> wrote:
> Hello List,
>
> Does anybody know of any plans to include support for the new datetime64
> data type in numpy? If this is the new numpy standard for doing dates and
> times, it would be great if it would work with plot_date, for example.
>
> Just wondering (but boy, would I do a little dance when all this datetime
> stuff is fully operational and integrated),


Should be fairly straightforward to write a converter.  Just follow
the example of DateConverter in matplotlib.dates
:https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/dates.py:

class DateConverter(units.ConversionInterface):
    """
Converter for datetime.date and datetime.datetime data,
or for date/time data represented as it would be converted
by :func:`date2num`.

The 'unit' tag for such data is None or a tzinfo instance.
"""

    @staticmethod
    def axisinfo(unit, axis):
        """
Return the :class:`~matplotlib.units.AxisInfo` for *unit*.

*unit* is a tzinfo instance or None.
The *axis* argument is required but not used.
"""
        tz = unit

        majloc = AutoDateLocator(tz=tz)
        majfmt = AutoDateFormatter(majloc, tz=tz)
        datemin = datetime.date(2000, 1, 1)
        datemax = datetime.date(2010, 1, 1)

        return units.AxisInfo( majloc=majloc, majfmt=majfmt, label='',
                               default_limits=(datemin, datemax))

    @staticmethod
    def convert(value, unit, axis):
        """
If *value* is not already a number or sequence of numbers,
convert it with :func:`date2num`.

The *unit* and *axis* arguments are not used.
"""
        if units.ConversionInterface.is_numlike(value):
            return value
        return date2num(value)

    @staticmethod
    def default_units(x, axis):
        'Return the tzinfo instance of *x* or of its first element, or None'
        try:
            x = x[0]
        except (TypeError, IndexError):
            pass

        try:
            return x.tzinfo
        except AttributeError:
            pass
        return None


units.registry[datetime.date] = DateConverter()
units.registry[datetime.datetime] = DateConverter()

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to