matplotlib: Plotting a graph against time

arsyed arsyed at
Sun Jul 20 23:06:32 CEST 2008

On Sun, Jul 20, 2008 at 9:57 AM, Durand <durand1 at> 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( it gave me datetime.datetime whereas the objects
> in this list are strings...Am I doing something wrong here?
> --

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

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list