Matplotlib 3D Surface缺少1个必需的位置参数:“Z”

2024-04-20 10:04:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着像这个例子一样制作3D曲面:https://gis.stackexchange.com/questions/66367/display-a-georeferenced-dem-surface-in-3d-matplotlib

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import *
from matplotlib.mlab import griddata
from matplotlib import cm

data = np.random.random((20, 2))
z = np.random.randint(5, 30, 20)
x = data.T[0]
y = data.T[-1]
xi = np.linspace(min(x), max(x))
yi = np.linspace(min(x), max(y))
X, Y = np.meshgrid(xi, yi)

Z = griddata(x, y, z, xi, yi)

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter3D(x, y, z, c=z)
Axes3D.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet, linewidth=1, antialiased=True)
plt.show()

我认为我的代码与示例类似,但不是这样 工作。我有这个错误

TypeError: plot_surface() missing 1 required positional argument: 'Z'

我怎样才能修好它?在


Tags: fromimportdatamatplotlibnpcmpltrandom
1条回答
网友
1楼 · 发布于 2024-04-20 10:04:12

你只需要使用你的三维轴对象来打印。为此,请更换

Axes3D.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet, linewidth=1, antialiased=True) 

通过

^{pr2}$

我甚至不知道为什么你一开始就使用Axes3D.plot_surface,甚至在定义了一个ax的对象{}之后。在

我(使用matplotlib版本2.2.2)也收到了一个警告

The griddata function was deprecated in version 2.2.

enter image description here

相关问题 更多 >