【发布时间】:2018-07-28 20:05:28
【问题描述】:
我正在尝试绘制一个穿过一组 (X,Y,Z) 3d 点的 3d 曲面,但我得到了 raise ValueError("Argument Z must be 2-dimensional.") matplotlib
points = Tail_geo(D,L) # is a list from a function
points = points + Nose_geo(D,L)# is a list from both function s
X = [x[0] for x in points]# seperate X from the list
Y = [x[1] for x in points]
Z = [x[2] for x in points]
X = np.asarray(X)
Y = np.asarray(Y)
Z = np.asarray(Z)
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, linewidth=0, antialiased=False)
plt . show ( )
【问题讨论】:
-
这段代码 sn-p 不完整,因为您没有显示函数
Tail_geo和Nose_geo的定义,也没有显示导入。这些事情可能很重要。请显示完整的代码 sn-p,我们可以复制并粘贴然后运行。还显示错误的完整回溯。检查How to create a Minimal, Complete, and Verifiable example。 -
在您的代码中
Z似乎也是一个一维列表。在 3d 表面中,对于一组X和X点,您需要这些X和Y点的网格,然后在每个n次 @987654332 处定义/计算Z@grid(假设len(X) = n; len(Y) = n)。使用当前数据,您可以绘制的只是 3d 散点图。如果您想了解更多信息,请分享您的代码。
标签: python matplotlib