Noob confusion: Pcolor

Thanks for your reply, Giorgio. I had a look at the documentation for pcolor but unfortunately, I can’t pick out where I have gone wrong. I have attached my data array as a txt file. In ipython, I use the ‘loadtxt’ command to load the dataset and then assigned the variables x,y, and z to the first, second and third columns respectively. I then specified the meshgrid X,Y from the x and y arrays of my data and used pcolor(X,Y,z) to try and plot the color map.

Thanks a lot!

195pt52_T6.txt (9.19 KB)

···

On Thu, Nov 12, 2009 at 4:36 AM, Giorgio_Luciano <giorgio_luciano@…1348…> wrote:

Can you send and example of the matrix you are using ?

Are you sure to have specified correct input according to

http://matplotlib.sourceforge.net/api/pyplot_api.html?highlight=pcolor#matplotlib.pyplot.pcolor

Cheers

Giorgio

You have to interpolate your 1D data onto a 2D grid --

In [504]: x,y,z = np.loadtxt('195pt52_T6.txt', unpack=True)

# create evenly sampled x and y vectors to interpolate onto
In [505]: xi = np.linspace(x.min(), x.max(), 20)

In [506]: yi = np.linspace(y.min(), y.max(), 20)

# use griddata to do the 2D interoplation
In [507]: Z = mlab.griddata(x, y, z, xi, yi)

In [508]: Z.shape
Out[508]: (20, 20)

# use meshgrid to create 2D grids of your 1D x and 1 data
In [509]: X, Y = np.meshgrid(xi, yi)

# pass all the 2D arrays to pcolor
In [510]: pcolor(X, Y, Z)
Out[510]: <matplotlib.collections.PolyCollection object at 0x113e6d8c>

Hope this helps!

···

On Wed, Nov 11, 2009 at 3:22 PM, Shrividya Ravi <pentheseleia@...287...> wrote: