我正在努力绘制以下数据集(下图)。数据集表示3D空间中的10个矩形特征。这些特征在Y轴上以3个单元格的距离间隔。X和Z列显示X和Z轴上的范围(单元格数)。输出应该是在Y方向上每3个单元格间隔10个矩形。矩形可以是任何颜色。
另一条信息(不确定是否相关),X,Y,Z方向的单元格数量是50个单元格。在现实生活中,每个单元格代表100英尺的距离。
我试过numpy.meshgrid,但没有成功。

发布于 2020-11-02 05:26:36
首先,你需要得到矩形的角点-这是相当直接的-它只是2 (x,z)角的4个组合,所有的点都显示了y值。
然后可以将矩形绘制为:
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
# Corner points of rectangles
feat1 = [(7,6,10),
(7, 6, 20),
(13, 6, 20),
(13, 6, 10)]
feat2 = [(2,9,13),
(2, 9, 17),
(18, 9, 17),
(18, 9, 13)]
feat3 = [(7,12,10),
(7, 12, 20),
(13, 12, 20),
(13, 12, 10)]
features = [feat1, feat2, feat3]
fig = plt.figure()
ax = Axes3D(fig)
facets = Poly3DCollection(features)
facets.set_facecolor(['blue', 'green', 'red'])
ax.add_collection3d(facets)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()这将返回如下所示的图:

https://stackoverflow.com/questions/64635697
复制相似问题