matplotlib breaks: ValueError: ordinal must be >= 1 from matplotlib/dates.py", line 170, in _from_ordinalf

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!

Please post a standalone example that reproduces your problem.
I tried your example with some junk data but no such exception is raised.

However, there has been a report of a similar ordinal value problem
which I think is not fixed yet, but that problem only occurs when two
and more axes are shared.

See if below helps,
* move the axhline call after the plotting commands.
* autoscale only after all the necessary plot elements are in place.

Again, please post a standalone example that reproduces your problem.

Regards,

-JJ

···

On Tue, Jul 14, 2009 at 9:50 AM, M Osborne<osbormd@...287...> wrote:

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 = \{ &#39;fontname&#39;:&#39;Tahoma&#39;, &#39;fontsize&#39;: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=&#39;r&#39;\)
   ax1\.set\_ylim\(0,100\)
   ax1\.autoscale\_view\(tight=False, scalex=True, scaley=False\)
   ax1\.plot\(timestamp, percentu, &#39;ko\-&#39; \)
   ax1\.plot\(timestamp, percentl, &#39;b\-\-&#39;, linewidth=2\)
   ax2 = fig\.add\_subplot\(212\)
   ax2\.grid\(True\)
   ax2\.plot\(predict\_x, predict\_y, &#39;bs\-\-&#39;, linewidth=2\)
   plt\.savefig\(&quot;plot\.pdf&quot;\)

Thank you in advance!

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users