Building terrain data using matplotlib plot_surface

I am trying to build elevation data using matplotlib. I create an nx3 numpy array with each row containing the x, y, z coordinates of my points (they are regularly placed in the grid on the x, y plane). I am trying to build it using this code:

fig = plt.figure() ax = fig.gca(projection='3d') print desiredData[:,0] surf = ax.plot_surface(desiredData[:,0], desiredData[:,1], desiredData[:,2], rstride =1, cstride = 1, cmap=cm.jet, linewidth = 0, antialiased = False) plt.show() 

but I get this error:

 Traceback (most recent call last): File "gisConvert.py", line 203, in <module> linewidth = 0, antialiased = False) File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 663, in plot_surface rows, cols = Z.shape ValueError: need more than 1 value to unpack 

What am I doing wrong?

+4
source share
1 answer

As the error shows,

 ValueError: need more than 1 value to unpack 

You are using a 1D array, but plot_surface expects 2D arrays for X , Y and Z

And that is why you get a ValueError .

+4
source

Source: https://habr.com/ru/post/1332726/


All Articles