简体   繁体   English

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

[英]Draw 3D Polygon Using Vertex Array Python (Matplotlib)

I need to draw polygons using vertex arrays in the form P = (X, Y, Z), a Cube would be represented by: 我需要使用顶点数组以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]

With that given I want to be able to draw the lines between the points and show the object in 3D, I already have matplotlib installed but if you have the solution for it using another library it's totally fine. 有了这个,我希望能够画出点之间的线并以3D显示对象,我已经安装了matplotlib,但是如果您有使用另一个库的解决方案,那是完全可以的。 By the way, I've already searched for similar topics but couldn't find help, I have also read the matplotlib docs but didn't find a way to do this. 顺便说一句,我已经搜索了类似的主题,但是找不到帮助,我也阅读了matplotlib文档,但没有找到解决方法。 Plotting 3D Polygons in python-matplotlib this doesnt either... Thanks! 在python-matplotlib中绘制3D多边形也没有...谢谢!

You need to use mplot3d along with basic pyplot: 您需要将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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM