Graph Dates and Values

Gabriel Genellina gagsl-py2 at
Tue Mar 10 15:40:13 CET 2009

En Tue, 10 Mar 2009 05:08:41 -0200, brianrpsgt1 <brianlong at>  

> I am trying to plot dates and values on a graph using matplotlib.
> Below is the code.  I can run this and it works great, until I get to
> about 2000 rows from the DB.  Things really start to slow down.  I
> have successfully plotted up to 5000 rows from the DB, but it is very
> slow.  I am attempting to plot values for a day, which would be equal
> to 84600 records.  Is there a more efficient may to accomplish this?

(isn't it 86400?)

> for s in value_data:
>     dates = mdates.date2num([s[0]])
>     plt.plot([dates],[s[1]], 'bo', ms=6)

Without looking at the matplotlib docs, the above [] suggests that both  
date2num and plt.plot take a list of values to act upon, and you're  
feeding one point at a time. Probably you end up creating one series per  
point (instead of a single series with many points). I guess something  
like this should work:

x, y = zip(*value_data) # "transpose"
dates = mdates.date2num(x)
plt.plot(dates, y, 'bo', ms=6)

(totally untested)

Gabriel Genellina

More information about the Python-list mailing list