0

I have three arrays such as follows:

x = np.array([x1,x2,....x400])
y = np.array([y1,y2,....y400])
z = np.array([z1,z2,....z400])

The x and y values define a 2d plane with a length and depth of 400 values each and z is the color (intensity) calculated from a function using x and y values.

I would like to plot a 2d contour plot and I have tried the following based on the post in here :

x_, y_ = np.meshgrid(x, y)
z_grid = np.array(z).reshape(400,400)
fig = plt.figure()
ax1 = plt.contourf(x_,y_,z_grid)
plt.show()

However, I am receiving the following error:

cannot reshape array of size 400 into shape (400,400)

What is the correct way to plot this 2D contour?

Sara Krauss
  • 388
  • 3
  • 17
  • z would need to be size 400 by 400, a value at every x,y location given by meshgrid. You would need to use x_ and y_ in your function to get z – Ed Smith Mar 11 '22 at 16:04
  • Actually the number of unique data in each variable is different. For example, if the ```x``` and the ```y``` variables have 400 points, their unique values are 200. Your ```z``` variable need to be reshaped to a 200x200 structure. – Gustavo Alves Apr 07 '22 at 02:17

0 Answers0