使用顶点数组 Python 绘制 3D 多边形 (Matplotlib)

Draw 3D Polygon Using Vertex Array Python (Matplotlib)

我需要使用 P = (X, Y, Z) 形式的顶点数组绘制多边形,立方体将表示为:

P1 = [0,0,0]
P2 = [0,1,0]
P3 = [1,0,1]
P4 = [0,1,1]
P5 = [1,1,1]
P6 = [1,1,0]
P7 = [1,0,0]
P8 = [0,0,1]

考虑到这一点,我希望能够在点之间绘制线条并以 3D 形式显示对象,我已经安装了 matplotlib,但如果您使用其他库来解决它,那就完全没问题了。 顺便说一句,我已经搜索过类似的主题但找不到帮助,我也阅读了 matplotlib 文档但没有找到执行此操作的方法。 Plotting 3D Polygons in python-matplotlib 这也不... 谢谢!

您需要将 mplot3d 与基本的 pyplot 一起使用:

 from mpl_toolkits.mplot3d import Axes3D
 import matplotlib.pyplot as plt
 from mpl_toolkits.mplot3d.art3d import Poly3DCollection
 fig = plt.figure()
 ax = Axes3D(fig)
 vertices = [zip(P1,P2,...)]
 ax.add_collection3d(Poly3DCollection(vertices))
 plt.show()