From: John H. <jdh...@ac...> - 2004-11-10 22:26:29
|
>>>>> "seberino" == seberino <seb...@sp...> writes: seberino> Stephen Thanks for the help. The format of the data is seberino> ASCII files and/or Python arrays that contain (x, y) seberino> coordinates or (x, y, z) coordinates for 3D. seberino> For starters, what is best way to plot triples in this seberino> list?... seberino> [ (0, 0, 3.3), (0, 1, 4.4), (1, 0, 2.2), (1, 1, 2.34)] seberino> I want to duplicate color plot on screenshots page: seberino> http://matplotlib.sourceforge.net/screenshots/pcolor_demo_large.png You have a 2x2 grid. pcolor is a bit funny in that for an MxN grid it only plots M-1 x N-1 rectangles since it doesn't know how to handle the edges. So it's a bit of a pathalogical case for pcolor. Basically you need to transform your list of 3 tuples into 3 arrays x,y,z, and then reshape the array. Here I'll use imshow which doesn't have the edge problem from matplotlib.matlab import * data = [ (0, 0, 3.3), (0, 1, 4.4), (1, 0, 2.2), (1, 1, 2.34)] x,y,z = zip(*data) z = array(z); z.shape = 2,2 imshow(z, interpolation='nearest', extent=(0,1,0,1)) show() If you had a longer data sequence, say 5x5, you would use pcolor like from matplotlib.matlab import * data = .... x,y,z = zip(*data) x = array(x); x.shape = 5,5 y = array(y); y.shape = 5,5 z = array(z); z.shape = 5,5 pcolor(x,y,z) show() In short, there is nothing special about plotting "data" versus "functions". Both are simply cases of plotting 1-D or 2-D arrays as far as matplotlib is concerned. Your task is to get your data in to the right array shape. JDH |