Hi,
on the following test case:
import numpy
import pylab
from matplotlib.dates import DateFormatter, HourLocator, MinuteLocator
fig = pylab.figure()
ax = fig.add_subplot(1,1,1)
tics = numpy.linspace(1.3,1.6,4)
for tic in tics:
t = numpy.linspace(tic, tic+0.01, 100)
ax.plot(t, numpy.random.randn(len(t)), 'b.')
ax.xaxis.set_major_formatter(DateFormatter("%H:%M"))
ax.xaxis.set_major_locator(HourLocator(interval=2))
ax.xaxis.set_minor_locator(MinuteLocator(interval=30))
pylab.show()
I got an OverflowError:
Traceback (most recent call last):
File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py",
line 284, in expose_event
self._render_figure(self._pixmap, w, h)
File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtkagg.py",
line 73, in _render_figure
FigureCanvasAgg.draw(self)
File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py",
line 392, in draw
self.figure.draw(renderer)
File "/usr/lib/python2.4/site-packages/matplotlib/figure.py", line
544, in draw
for a in self.axes: a.draw(renderer)
File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line
1063, in draw a.draw(renderer)
File "/usr/lib/python2.4/site-packages/matplotlib/axis.py", line 545,
in draw
majorTicks = self.get_major_ticks()
File "/usr/lib/python2.4/site-packages/matplotlib/axis.py", line 683,
in get_major_ticks
numticks = len(self.major.locator())
File "/usr/lib/python2.4/site-packages/matplotlib/dates.py", line
450, in __call__
self.rule.set(dtstart=dmin-delta, until=dmax+delta)
File "/usr/lib/python2.4/site-packages/dateutil/relativedelta.py",
line 289, in __rsub__
return self.__neg__().__radd__(other)
File "/usr/lib/python2.4/site-packages/dateutil/relativedelta.py",
line 276, in __radd__
microseconds=self.microseconds))
OverflowError: date value out of range
Note that if everything works properly if:
* I start tics at 1.4 instead of 1.3
* *or* I remove calls to set_major_locator and set_minor_locator
Now, if I set tics=numpy.linspace(1.4,2.6,4), I got the following error:
Traceback (most recent call last):
File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py",
line 284, in expose_event
self._render_figure(self._pixmap, w, h)
File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_gtkagg.py",
line 73, in _render_figure
FigureCanvasAgg.draw(self)
File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py",
line 392, in draw
self.figure.draw(renderer)
File "/usr/lib/python2.4/site-packages/matplotlib/figure.py", line
544, in draw
for a in self.axes: a.draw(renderer)
File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line
1063, in draw a.draw(renderer)
File "/usr/lib/python2.4/site-packages/matplotlib/axis.py", line 545,
in draw
majorTicks = self.get_major_ticks()
File "/usr/lib/python2.4/site-packages/matplotlib/axis.py", line 683,
in get_major_ticks
numticks = len(self.major.locator())
File "/usr/lib/python2.4/site-packages/matplotlib/dates.py", line
450, in __call__
self.rule.set(dtstart=dmin-delta, until=dmax+delta)
File "/usr/lib/python2.4/site-packages/matplotlib/dates.py", line
391, in set
self._rrule = rrule(**self._construct)
File "/usr/lib/python2.4/site-packages/dateutil/rrule.py", line 238,
in __init__
dtstart = dtstart.replace(microsecond=0)
ValueError: month must be in 1..12
except if once again, I remove calls to set_major_locator and
set_minor_locator... (I definitely dont understand this last error about
an invalid month, since I thought times were supposedly in days since
0001-01-01 00:00:00 UTC.)
Last thing, is there any reason why t=0 is an invalid number of days? Eg.
In [4]: num2date(0)
/usr/lib/python2.4/site-packages/matplotlib/dates.py in num2date(x, tz)
213 """
214 if tz is None: tz = _get_rc_timezone()
--> 215 if not iterable(x): return _from_ordinalf(x, tz)
216 else: return [_from_ordinalf(val, tz) for val in x]
217
/usr/lib/python2.4/site-packages/matplotlib/dates.py in
_from_ordinalf(x, tz)
152 if tz is None: tz = _get_rc_timezone()
153 ix = int(x)
--> 154 dt = datetime.datetime.fromordinal(ix)
155 remainder = float(x) - ix
156 hour, remainder = divmod(24*remainder, 1)
ValueError: ordinal must be >= 1
First valid date number is indeed 1, but this corresponds to 0001-01-01
00:00:00 UTC:
In [10]: num2date(1).isoformat()
Out[10]: '0001-01-01T00:00:00+00:00'
and not to 0001-01-02. I suspect the documentation for num2date is
therefore not accurate... or is it just that I missed something?
Cheers.
--
.~. Yannick COPIN (o:>* Doctus cum libro
/V\ ---===<<<### NOT IN THE OFFICE ###>>>===---
// \\ Institut de physique nucleaire de Lyon (IN2P3 - France)
/( )\ http://snovae.in2p3.fr/ycopin/
^`~'^
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users