I have 3600 x values and 3600 y values. And an array (180x20). I need to plot it as contourplot and assign the first x value and the first y value, to the first array-value (A[0,0]) and so on... How can I do that?
My idea:
x,y = np.meshgrid(x,y)
plt.contourf(x,y,A)
Doesnt work: TypeError: Shape of x does not match that of z: found (3600, 3600) instead of (180, 20). I understand the error, but dont know how to solve it.
I think you're a bit confused on what meshgrid does. It sounds like you just want
reshape.An explanation of
numpy.meshgridAs an example of what meshgrid does, let's say we have a 5x5 grid of "z" values:
And we have the x-coordinates for a row and the y-coordinates for a column:
So, at this point, we have:
numpy.meshgridis meant to take those 1D arrays of column and row coordinates and turn them into 2D arrays that match the shape ofz:This yields:
Working with the data you have
If I'm understanding you correctly, your x and y arrays are each 3600-element lists, and your z-array is 180x20. (Note that
180 * 20 == 3600) Therefore, I think the data you have is equivalent to doing:Obviously, your data is a lot larger, but if we extend the example above, it would look like:
Therefore, you just want to reshape your lists into a 2D array of the same shape as
z. For example:yields
In other words, you want:
plt.contourf(np.reshape(yourx, z.shape), np.reshape(youry, z.shape), z)