作者:我爱左_470 | 来源:互联网 | 2022-12-09 12:31
我试图绘制通过一组(X,Y,Z)3d点的3d曲面,并且出现了ValueError(“ Argument Z必须是二维的。”)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 ( )
小智..
5
该函数plot_surface
期望其输入被构造为常规2D网格。对于您的数据(x,y,z作为列表),使用该plot_trisurf
函数可能更合适。只需在代码中进行简单的替换即可。
surf = ax.plot_trisurf(X, Y, Z, linewidth=0, antialiased=False)
在matplotlib画廊中有一个很好的示例,在这里https://matplotlib.org/examples/mplot3d/trisurf3d_demo.html,您可以浏览一下以了解更多详细信息。
1> 小智..:
该函数plot_surface
期望其输入被构造为常规2D网格。对于您的数据(x,y,z作为列表),使用该plot_trisurf
函数可能更合适。只需在代码中进行简单的替换即可。
surf = ax.plot_trisurf(X, Y, Z, linewidth=0, antialiased=False)
在matplotlib画廊中有一个很好的示例,在这里https://matplotlib.org/examples/mplot3d/trisurf3d_demo.html,您可以浏览一下以了解更多详细信息。