Reputation: 10131
I'm trying to plot values as a function of the date (only hh:mm:ss, without dd/mm/yy). The code looks like this
dates = matplotlib.dates.date2num(x_values)
plt.plot_date(dates, y_values)
but I get the following error
'numpy.string_' object has no attribute 'toordinal'.
Upvotes: 6
Views: 9424
Reputation: 373
from matplotlib import pyplot as plt <br>
pay_date=['2016-04-30', '2016-06-28', '2016-11-29']
due_date=['2016-05-02', '2016-07-31', '2016-10-29']
plt.plot_date(pay_date,due_date,xdate=True,ydate=True)
Just add the parameters xdate=True
and ydate=True
and it will automatically plot the dates
and finally write the following code, to print the lines
plt.plot(pay_date,due_date)
Upvotes: 0
Reputation: 108512
According to the docs:
matplotlib.dates.date2num(d): d is either a datetime instance or a sequence of datetimes.
Looks like you are giving in a string.
Upvotes: 2
Reputation: 284552
date2num
expects datetime
objects. If you have strings, use matplotlib.dates.datestr2num
.
Upvotes: 16