Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 829
Augusto Dias Noronha Avatar asked Nov 03 '25 12:11

Augusto Dias Noronha


1 Answers

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)
like image 75
Martijn Pieters Avatar answered Nov 06 '25 02:11

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!