En Tue, 10 Mar 2009 13:32:10 -0200, brianrpsgt1 <brianl...@cox.net> escribió:
On Mar 10, 7:40 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Tue, 10 Mar 2009 05:08:41 -0200, brianrpsgt1 <brianl...@cox.net>  
escribió:

> 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?

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)


Thanks for the notes.  That is exactly what I thought the problem
was.  Here is an update.  I put a limit to 100 on the SQL Query to
test.  When I run your code, I get the data returned, however, I get
the same return equal to the limit I set.  In other words, when I run
with a limit of 100, I get the same result 100 times.  Which would
mean that when I try to run a whole day (86400 :) - it was late!), I
am getting the same result 86400 times and then it is tyring to plot
that.

Output below:

[ 733414.06489583  733414.06490741  733414.06491898  733414.06493056 ...
  733414.06600694  733414.06601852  733414.06603009  733414.06604167]
(95, 95, 95, 95, ...  95, 95, 95, 94)

If I run this code:

for s in value_data:
    x = mdates.date2num([s[0]])
    y = [s[1]]
    print [x, y]

The results returned are the following:

There are 100 rows in the database
[ 733414.06489583] [95]
[ 733414.06490741] [95]
[ 733414.06491898] [95]
[ 733414.06493056] [95] ...
[ 733414.06600694] [95]
[ 733414.06601852] [95]
[ 733414.06603009] [95]
[ 733414.06604167] [94]

Well, both look the same values to me... what's wrong? Why do you say "the same results 100 times".

Oh, the code fragment I posted is suposed to *replace* the original for loop. Don't put it inside a loop.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to