6

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

3 Answers 3

16

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0
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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.