有人可以向我解释或向我展示如何使用Python中的2D线绘图命令创建3D线框多边形房屋吗?我知道我需要一组顶点并将它们连接成2D线然后绘制它们。我只是不完全确定如何做到这一点。
答案 0 :(得分:1)
基于各种3D形状的优秀answer,你可以做类似的事情,
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
# draw cube
r = [-1, 1]
points = list(product(r, r, r))
#Add roof
points.append([0., 1.5, -1.])
points.append([0., 1.5, 1.])
#Convert to array
points = np.array(points)
#Plot
ax.scatter(points[:,0], points[:,1], points[:,2])
for s, e in combinations(points, 2):
#All diagonals will be greater than 2
if np.sum(np.abs(s-e)) <= 2:
ax.plot3D(*zip(s, e), color="k")
plt.show()
然后看起来像这样,