import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
fig = plt.figure()
ax = fig.gca(projection='3d')
# 正文体顶点和面
# verts = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0), (0, 0, 1), (0, 1, 1), (1, 1, 1), (1, 0, 1)]
# faces = [[0, 1, 2, 3], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [0, 3, 7, 4]]
# 获得每个面的顶点
poly3d = [[verts[vert_id] for vert_id in face] for face in faces]
# print(poly3d)
# 绘制顶点
x, y, z = zip(*verts)
ax.scatter(x, y, z)
# 绘制多边形面
ax.add_collection3d(Poly3DCollection(poly3d, facecolors='w', linewidths=1, alpha=1))
# 绘制对变形的边
ax.add_collection3d(Line3DCollection(poly3d, colors='k', linewidths=0.5, linestyles=':'))
# 设置图形坐标范围
ax.set_xlabel('X')
ax.set_xlim3d(0, 2)
ax.set_ylabel('Y')
ax.set_ylim3d(0, 2)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 2)
plt.show()
这个代码绘制出来是个3d正方形,上面的两个数组代表每个点的坐标(分别是x,y,z), 第二个数组愣是没明白,谁能讲讲
注:代码来源:
matplotlib模块数据可视化-3D图_sinat_36772813的博客-CSDN博客
1 matplotlib绘制3D图形matplotlib可以绘制3D图形,有的版本中不具备该模块,可以进入python环境,输入from mpl_toolkits.mplot3d import Axes3D进行测试,如果导入成功则可以,否则需要安装matplotlib其他版本,这里我用的是2.0.2版本。2 绘制3D画面图2.1 源码import numpy as npimpor
https://blog.csdn.net/sinat_36772813/article/details/77365296