Augusto Dias Noronha
Augusto Dias Noronha

Reputation: 864

Matplotlib and datetime error date2num function AttributeError

I'm trying to plot a graph with a list of datetime objects as one axis. I searched online and it seems I should call the date2num function. However, when I call it I get an Attribute error.

Here's the code I wrote:

listOfDates
[datetime.date(2013, 8, 20), datetime.date(2013, 8, 21)]
dates = mathplotlib.dates.date2num(listOfDates)

Here's the error I get:

Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
  dates = matplotlib.dates.date2num(listOfDates)
AttributeError: 'module' object has no attribute 'dates'

Thank you very much

Upvotes: 4

Views: 7814

Answers (2)

Nikhil Kumar
Nikhil Kumar

Reputation: 1

this error usually comes up when the date and time of your system is not correct. just correct and restart the whole console and it should work perfect.

Upvotes: 0

Martijn Pieters
Martijn Pieters

Reputation: 1123072

You need to import the matplotlib.dates module explicitly:

import matplotlib.dates

before it is available.

Alternatively, import the function into your local namespace:

from matplotlib.dates import date2num

dates = date2num(listOfDates)

Upvotes: 5

Related Questions