Skip to content Skip to sidebar Skip to footer

Importing Pandas In Python Changes How Matplotlib Handles Datetime Objects?

On my debian squeeze system, I ran into a python problem that can be distilled to the following: import numpy import datetime from matplotlib import pyplot x = [datetime.datetime.u

Solution 1:

When you import pandas it registers a bunch of unit converters with matplotlib. This is from more updated versions of both libraries, but I assume that the overall behavior is the same.

In [4]: import matplotlib.units as muints

In [5]: muints.registry
Out[5]: 
  {datetime.date: <matplotlib.dates.DateConverter instance at 0x2ab8908>,
   datetime.datetime: <matplotlib.dates.DateConverter instance at 0x2ab8ab8>}


In [6]: import pandas

In [7]: muints.registry
Out[7]: 
{pandas.tseries.period.Period: <pandas.tseries.converter.PeriodConverter instance at 0x2627e60>,
 pandas.tslib.Timestamp: <pandas.tseries.converter.DatetimeConverter instance at 0x264ea28>,
 datetime.date: <pandas.tseries.converter.DatetimeConverter instance at 0x2532fc8>,
 datetime.datetime: <pandas.tseries.converter.DatetimeConverter instance at 0x2627ab8>,
 datetime.time: <pandas.tseries.converter.TimeConverter instance at 0x2532f38>}

This registry is used by axis (with a few layers of re-direction) to determine how to format information that is not numbers and it matches on the class of the thing it is trying to label with (hence, the entries in the dictionary keyed to datetime.*).

I suspect you can fix this by replacing the offending entries in dict


Post a Comment for "Importing Pandas In Python Changes How Matplotlib Handles Datetime Objects?"