Draw terrain data using Matplotlib Plot_surface

I am trying to use matplotlib to plot terrain elevation data. I have created an nx3 numpy array, each row contains the x, y, z coordinates of my point (they are on the x, y plane Is regularly spaced in the grid). I tried to draw it with 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
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?

As the error shows,

< pre>ValueError: need more than 1 value to unpack

You are using a 1D array, but plot_surface requires a 2D array of X, Y and Z.

This is where you get ValueError Reason.

I am trying to plot terrain elevation data using matplotlib. I have built an nx3 numpy array, each row contains the x, y, z coordinates of my point (they It is regularly spaced in the grid on the x and y plane). I tried to draw it with 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
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?

As the error shows,

ValueError: need more than 1 value to unpack< /pre> 

You are using a 1D array, but plot_surface requires a 2D array of X, Y, and Z.

This is why you get ValueError.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1527 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.