我尝试通过mpl_toolkits.mplot3d和Axe.add_collection3d(Poly3DCollection())在平面上显示一个框。但是,当我旋转视图时,会发生一些叠加错误:橙色立方体部分被蓝色平面隐藏
Here is the correct display I'd like to have on every view和那里 the issues I'd like to fix
我想修复这些错误,但是我无法使用Alpha ...
这是我当前的代码:
from matplotlib import pyplot as plt
from c import Poly3DCollection
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
#Ground
Ground_vertices = np.array([[0,0,0], [5, 0, 0], [5, 5, 0], [0, 5, 0]])
ax.scatter3D(Ground_vertices[:, 0], Ground_vertices[:, 1], Ground_vertices[:, 2])
Ground_faces = [e for e in Ground_vertices]
ax.add_collection3d(Poly3DCollection([Ground_faces], facecolors="lavender"))
#Box
Box_vertices = np.array([[2,2,0], [3, 2, 0], [3, 3, 0], [2, 3, 0], [2, 2, 1], [3, 2, 1], [3, 3, 1], [2, 3, 1]])
ax.scatter3D(Box_vertices[:, 0], Box_vertices[:, 1], Box_vertices[:, 2], color="darkorange")
Box_faces = [
[Box_vertices[0], Box_vertices[1], Box_vertices[2], Box_vertices[3]],
[Box_vertices[0], Box_vertices[1], Box_vertices[5], Box_vertices[4]],
[Box_vertices[0], Box_vertices[3], Box_vertices[7], Box_vertices[4]],
[Box_vertices[1], Box_vertices[2], Box_vertices[6], Box_vertices[5]],
[Box_vertices[2], Box_vertices[3], Box_vertices[7], Box_vertices[6]],
[Box_vertices[5], Box_vertices[6], Box_vertices[7], Box_vertices[4]]
]
ax.add_collection3d(Poly3DCollection(Box_faces, facecolors="bisque", linewidths=1, edgecolors="darkorange"))
plt.show()
感谢您的帮助