|
From: Darren D. <dd...@co...> - 2005-05-04 17:00:18
|
On Wednesday 04 May 2005 12:54 pm, Michael J. Rehberg wrote: > Hello list, > > So far I'm pleased with matplotlib and python. I'm a pretty new user and > find the coding very rapid and the ability to glue different database and > statistical programs together pretty slick. I have a question. > > I am retrieving data from a database using an ODBC connection. When I > print the result set, "sql_result_set", looks like this, a list of tuples > (I think?): > > [(31773, 60.691), (31772, 61.991), ...and so on... (31774, 60.779)] > > Each tuple contains the X value and Y value for each coordinate on the line > plot I wish to make. > > After experimentation, I found that I could extract 2 vectors, one for x > and one for y, by doing this: > > x_value = [thisrow[0] for thisrow in sql_result_set] > y_value = [thisrow[1] for thisrow in sql_result_set] > > and then fed the result into plot > > plot(x_value, y_value) > > Now this works, but seems an inefficient way to do this. > > Is there a way to force the plot(x,y) command to recognize my > "sql_result_set" as a list of x,y tuples, instead of splitting the set into > two vectors? This would seem a natural way for plot to operate. Somehow I > think the "apply" notation, "*" or "**", might do this, but I'm stuck. > > Thanks for your ideas. Please let me know if I missed the obvious. Hi Michael, You can use a LineCollection for this. Check out line_collections.py in the examples directory (in CVS, not included with mpl-0.80). Darren -- Darren S. Dale Bard Hall Department of Materials Science and Engineering Cornell University Ithaca, NY. 14850 dd...@co... |