[egenix-users]
Matplotlib (pylab) datetime incompatible with Egenix mxDateTime
Simon Hook
simon.j.hook at jpl.nasa.gov
Sun Jul 16 13:01:46 CEST 2006
Hi,
[cross posted to egenix and matplotlib]
I have been using the egenix mxDateTime module and want to plot some of
the dates with Matplotlib (pylab). Pylab uses num2date and date2num to
covert datesandtimes to floating point values for plotting.
Unfortunately if you give pylab date2num an egenix DateTime object,
pylab bombs. Is there a simple way to use egenix DateTime objects with
Pylab?
Below is a simple example
#D:\apps\Python23\python.exe
from datetime import *
from mx.DateTime import *
from pylab import *
# This works
a=datetime(2005,10,10,5,5,5)
print a
# This works
b=DateTime(2005,10,10,5,5,5)
print b
# This works
c=date2num(a)
print c
# This fails
d=date2num(b)
print d
The output and failure message is:
2005-10-10 05:05:05
2005-10-10 05:05:05.00
732229.211863
Traceback (most recent call last):
File "datetime-problem.py", line 20, in ?
d=date2num(b)
File "D:\apps\Python23\lib\site-packages\matplotlib\dates.py", line
174, in da
te2num
if not iterable(d): return _to_ordinalf(d)
File "D:\apps\Python23\lib\site-packages\matplotlib\dates.py", line
137, in _t
o_ordinalf
base = dt.toordinal()
AttributeError: toordinal
thanks, Simon
More information about the egenix-users
mailing list