【发布时间】:2022-01-02 04:53:54
【问题描述】:
【问题讨论】:
标签: python matplotlib scatter-plot
【问题讨论】:
标签: python matplotlib scatter-plot
您需要定义顶点的位置,以及需要连接的边。假设您已在某个列表 AllEdgesVertexPairs 中将一组边定义为顶点对,请让 matplotlib 为每一对创建一条线。
#Plot a line segment for each edge pair:
for SingleEdgeVertexPair in AllEdgesVertexPairs:
Vertex1 = SingleEdgeVertexPair[0]
Vertex2 = SingleEdgeVertexPair[1]
EdgeXvals = [Vertex1[0], Vertex2[0] ]
EdgeYvals = [Vertex1[1], Vertex2[1] ]
EdgeZvals = [Vertex1[2], Vertex2[2] ]
matplotlib.pyplot.plot(
EdgeXvals,
EdgeYvals,
EdgeZvals,
c='k',
marker=None,
linestyle = '-',
linewidth = 0.2,
)
在我自己的一个特殊情况下,我需要绘制一个立方体,所以我的 AllEdgesVertexPairs 看起来像:
[[[ 16. 16. 115.]
[-14. 16. 115.]]
[[ 16. 16. 115.]
[ 16. -14. 115.]]
[[ 16. 16. 115.]
[ 16. 16. 85.]]
[[-14. 16. 115.]
[-14. -14. 115.]]
[[-14. 16. 115.]
[-14. 16. 85.]]
[[ 16. -14. 115.]
[-14. -14. 115.]]
[[ 16. -14. 115.]
[ 16. -14. 85.]]
[[-14. -14. 115.]
[-14. -14. 85.]]
[[ 16. 16. 85.]
[-14. 16. 85.]]
[[ 16. 16. 85.]
[ 16. -14. 85.]]
[[-14. 16. 85.]
[-14. -14. 85.]]
[[ 16. -14. 85.]
[-14. -14. 85.]]]
在您的情况下,您还需要 8 个顶点和 12 个边。但是,您将如何选择它们并不是很明显。
如果您需要一种算法来根据您的图像自己选择边界顶点,我建议如下:
通过使用 PCA 和直角棱镜,您可以对“边界框”内的点数做出数学陈述。 (您基本上是在用一个矩形框逼近从多元高斯派生的椭圆体)。那里可能有更好或更聪明的算法。
【讨论】: