matplotlib: Plotting a graph against time

arsyed arsyed at gmail.com
Sun Jul 20 23:06:32 CEST 2008


On Sun, Jul 20, 2008 at 9:57 AM, Durand <durand1 at gmail.com> wrote:

> Oooh, this is almost what I want but I'm not really sure how I'd
> incorporate this into real dates...
> If I have a list of dates like ['2008-07-18 14:36:53.494013',
> '2008-07-20 14:37:01.508990', '2008-07-28 14:49:26.183256'], how would
> I convert it to a format that pylab can understand? When I tried
> type(datetime.now()) it gave me datetime.datetime whereas the objects
> in this list are strings...Am I doing something wrong here?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


To convert strings to date, you can use datetime.strptime but it doesn't
seem to handle fractional seconds.  I usually opt for the dateutil module
[1]:

import dateutil, pylab

datestrings = ['2008-07-18 14:36:53.494013','2008-07-20 14:37:01.508990',
'2008-07-28 14:49:26.183256']
dates = [dateutil.parser.parse(s) for s in datestrings]
pylab.plot_date(pylab.date2num(dates), values, linestyle='-')

where values is the list of corresponding y-values.


[1] http://labix.org/python-dateutil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080720/ea68613a/attachment.html>


More information about the Python-list mailing list