简体   繁体   English

使用matplotlib plot_surface绘制地形数据

[英]Plotting terrain data with matplotlib plot_surface

I'm trying to plot terrain elevation data with matplotlib. 我正在尝试使用matplotlib绘制地形高程数据。 I build up a nx3 numpy array, with each row containing the x, y, z coordinates of my points (they're regularly spaced in a grid on the x, y plane). 我建立了一个nx3 numpy数组,每行包含我的点的x,y,z坐标(它们在x,y平面上的网格中有规律地间隔开)。 I am attempting to plot 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'm getting 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? 我究竟做错了什么?

As the error suggests, 正如错误所示,

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 . 您正在使用1D阵列,但plot_surface需要XYZ 2D阵列。

And that is why you get the ValueError . 这就是你得到ValueError

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM