From: Robert K. <rob...@gm...> - 2006-04-29 18:12:32
|
Michael V. De Palatis wrote: > On Sat, Apr 29, 2006 at 09:59:14AM -0700, Andrew Straw wrote: > >>If you data is regularly spaced, you can just use imshow or pcolor. If >>it's not regularaly spaced, see >>http://www.scipy.org/Wiki/Cookbook/Matplotlib/Gridding_irregularly_spaced_data > > Perhaps I'm missing something or did not explain my problem > properly. I am well aware that what I want to use is imshow (or, > apparently, pcolor). However, my problem is that I have all THREE > values in data form, not just x and y (that is, I do not have a > function to get z(x, y), but rather I have data points for z). > > I do not see a straightforward way to use imshow or pcolor to be able > to plot this data as they want a matrix that I have no idea how to > generate. Okay, so your x,y data is regularly spaced. What you have to do is create an array of the appropriate size to put all of your z values in. Then go through your list of points and populate the z array in the appropriate places. You will have to convert your x,y coordinates into i,j indices. If you know the spacing, this should not be difficult. Alternatively, you can sort the (x,y,z) tuples, turn it into an array, extract the z column, reshape the z column into the appropriate matrix, and transpose it (presuming you want y to be vertical): In [18]: xyz = [(1, 0, 10), (0, 1, 20), (0, 0, 30), (1, 1, 40)] In [19]: xyz.sort() In [20]: xyz Out[20]: [(0, 0, 30), (0, 1, 20), (1, 0, 10), (1, 1, 40)] In [21]: xyza = array(xyz) In [22]: z = xyza[:,-1] In [23]: z Out[23]: array([30, 20, 10, 40]) In [24]: z = transpose(reshape(z, (2,2))) In [25]: z Out[25]: array([[30, 10], [20, 40]]) -- Robert Kern rob...@gm... "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |