使用 matplotlibplot_surface 绘制地形数据
我正在尝试使用 matplotlib 绘制地形高程数据。我建立了一个 nx3 numpy 数组,每行包含我的点的 x、y、z 坐标(它们在 x、y 平面上的网格中规则间隔)。我试图用这段代码绘制它:
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()
但我收到此错误:
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
我做错了什么?
I'm trying to plot terrain elevation data with 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). 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如错误所示,
您正在使用一维数组,但
plot_surface
需要X
、Y
和Z
的二维数组>。这就是您收到
ValueError
的原因。As the error suggests,
You are using a 1D-array but
plot_surface
expects 2D arrays forX
,Y
andZ
.And that is why you get the
ValueError
.