Some Matplotlib methods need days in \'float days format\'. datestr2num is a converter function for this, but it falls over with the relevant pandas objects:
You can use the to_pydatetime
method of the DatetimeIndex (this will convert it to an array of datetime.datetime
's, and mpl.dates.date2num
will know how to handle those):
mpl.dates.date2num(df.index.to_pydatetime())
The reason that date2num
does not natively handle a pandas DatetimeIndex, is because matplotlib does not yet support the numpy datetime64 dtype (which is how the data are stored in a DatetimeIndex).