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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With