首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python中的Plot3d

Python中的Plot3d
EN

Stack Overflow用户
提问于 2016-05-26 20:08:10
回答 1查看 950关注 0票数 2

我有一个OBJ文件,由Meshlab生成的顶点和脸数据。在MATLAB中,我在另一个数组(5937x3)和面(11870x3)数据中使用了带有顶点数据的“补丁”函数,结果如下:

代码语言:javascript
复制
Simplified version of the code

[V,F] = read_vertices_and_faces_from_obj_file(filename);

patch('Vertices',V,'Faces',F,'FaceColor','r','LineStyle','-')

axis equal

结果

问题是,我如何在Python中做到这一点?有一种类似于Matlab的简单方法??

我真的很感激你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-26 21:02:29

最好的选择是利用来自matplotlib库的matplotlib

这里也问了一个类似的问题。也许从这个问题中略作编辑的代码摘录将对您有所帮助。

代码:

代码语言:javascript
复制
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt

fig = plt.figure()
ax = Axes3D(fig)
# Specify 4 vertices
x = [0,1,1,0] # Specify x-coordinates of vertices
y = [0,0,1,1] # Specify y-coordinates of vertices
z = [0,1,0,1] # Specify z-coordinates of vertices
verts = [zip(x, y, z)] # [(0,0,0), (1,0,1), (1,1,0), (0,1,1)]
tri = Poly3DCollection(verts) # Create polygons by connecting all of the vertices you have specified
tri.set_color(colors.rgb2hex(sp.rand(3))) # Give the faces random colors
tri.set_edgecolor('k') # Color the edges of every polygon black
ax.add_collection3d(tri) # Connect polygon collection to the 3D axis
plt.show()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37470076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档