Your data just needs to be reshaped. No need to use np.meshgrid
here, since you already have an x and y coord for each cell.
If you have nx
coordinates in x, and ny
coordinates in y, then you can do this:
X = dat['X'].reshape(nx,ny).T
Y = dat['Y'].reshape(nx,ny).T
Z = dat['Z'].reshape(nx,ny).T
plt.pcolormesh(X,Y,Z)
plt.show()
Note that pcolormesh prefers that you have your x
and y
dimensions be one greater that the z
dimension, since x
and y
define the edges of the cells, and z
defines the colour at the cell centre. From the docs:
Ideally the dimensions of X and Y should be one greater than those of C; if the dimensions are the same, then the last row and column of C will be ignored.
So, in you example, the colours from the final row and column will be lost, unless you add a row and column of dummy cells with x and y coordinates 1 greater than your number of cells. An alternative might be to use plt.contourf
, for which x, y, and z should be the same length.