Date formatting on axis tick marks fails with "ValueError: ordinal must be >= 1"

Hello,

I am having trouble setting the formatting for date objects that are displayed on the tick marks of one graph that I am making. The following example code reproduces the problem for me:

from datetime import date

import matplotlib.dates as mdate

import matplotlib.pyplot as plt

p1 = plt.subplot(211)

p1.yaxis.set_major_formatter(mdate.DateFormatter(’%b %d’, None))

plt.plot([date(2002, 3, 10)], [1])

The traceback that I am getting is as follows:

Traceback (most recent call last):

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py”, line 798, in draw

func(*args)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py”, line 1934, in draw

a.draw(renderer)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py”, line 971, in draw

tick_tups = [ t for t in self.iter_ticks()]

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py”, line 907, in iter_ticks

majorLabels = [self.major.formatter(val, i) for i, val in enumerate(majorLocs)]

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 335, in call

dt = num2date(x, self.tz)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 289, in num2date

if not cbook.iterable(x): return _from_ordinalf(x, tz)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 203, in _from_ordinalf

dt = datetime.datetime.fromordinal(ix)

ValueError: ordinal must be >= 1

Any idea what I could be doing wrong with my formatting here? I am using Matplotlib version 1.0.0. Thanks very much,

Adrian

Solved my own bone-headded problem. I should have been using “p1.xaxis” instead of “p1.yaxis”. Sorry for the pointless post.

Adrian

2010/12/4 Adrian <adrian.down@…2664…>

···

Hello,

I am having trouble setting the formatting for date objects that are displayed on the tick marks of one graph that I am making. The following example code reproduces the problem for me:

from datetime import date

import matplotlib.dates as mdate

import matplotlib.pyplot as plt

p1 = plt.subplot(211)

p1.yaxis.set_major_formatter(mdate.DateFormatter(’%b %d’, None))

plt.plot([date(2002, 3, 10)], [1])

The traceback that I am getting is as follows:

Traceback (most recent call last):

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py”, line 798, in draw

func(*args)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py”, line 1934, in draw

a.draw(renderer)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py”, line 971, in draw

tick_tups = [ t for t in self.iter_ticks()]

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py”, line 907, in iter_ticks

majorLabels = [self.major.formatter(val, i) for i, val in enumerate(majorLocs)]

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 335, in call

dt = num2date(x, self.tz)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 289, in num2date

if not cbook.iterable(x): return _from_ordinalf(x, tz)

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 203, in _from_ordinalf

dt = datetime.datetime.fromordinal(ix)

ValueError: ordinal must be >= 1

Any idea what I could be doing wrong with my formatting here? I am using Matplotlib version 1.0.0. Thanks very much,

Adrian