Simon Hook wrote: > 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
I'm not sure what date2num() uses as epoch, but it looks like some variant of a Julian Day Number: >>> b.jdn 2453653.711863426 >>> b.tjd 3653.2118634259259 > 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 .toordinal() is a datetime method which is not supported by mxDateTime instances. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 16 2006) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: ------------------------------------------------------------------------- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users