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

时间:2015-09-21 23:09:21

标签: python opengl matplotlib 3d

我需要使用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这不是...... 谢谢!

1 个答案:

答案 0 :(得分:1)

你需要使用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()