Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib with dates

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'.

like image 598
Bob Avatar asked Jun 18 '12 22:06

Bob


Video Answer


2 Answers

date2num expects datetime objects. If you have strings, use matplotlib.dates.datestr2num.

like image 101
Joe Kington Avatar answered Nov 14 '22 21:11

Joe Kington


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.

like image 21
Mark Avatar answered Nov 14 '22 22:11

Mark