I am trying to plot some historical trend data, where x is a date and
y is a percentage.
When I try to insert a horizontal line with ax1.axhline(y=80,
linewidth=1, color='r'), matplotlib breaks, with an error "
ValueError: ordinal must be >= 1".
The Traceback most recent call is, File
"/usr/lib64/python2.4/site-packages/matplotlib/dates.py", line 170, in
_from_ordinalf
dt = datetime.datetime.fromordinal(ix)"
Without the axhline element, matplotlib handles the data fine, and
plots nice weekly dates.
I'm guessing based on the error that axhline is manually forcing
autoscale off and/or matplotlib can no longer interpret the date
values for x?
Below is the matplotlib snippet of my code:
fig = plt.figure(figsize=(20,10))
font = { 'fontname':'Tahoma', 'fontsize':12 }
ax1 = fig.add_subplot(211)
ax1.set_ylim(0,100)
ax1.autoscale_view(tight=False, scalex=True, scaley=False)
ax1.grid(True)
ax1.axhline(y=80, linewidth=1, color='r')
ax1.set_ylim(0,100)
ax1.autoscale_view(tight=False, scalex=True, scaley=False)
ax1.plot(timestamp, percentu, 'ko-' )
ax1.plot(timestamp, percentl, 'b--', linewidth=2)
ax2 = fig.add_subplot(212)
ax2.grid(True)
ax2.plot(predict_x, predict_y, 'bs--', linewidth=2)
plt.savefig("plot.pdf")
Thank you in advance!