从圆多边形得到坐标matplotlib.patches补丁程序

2024-09-30 18:22:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的代码,它使用Python matplotlib生成一个圆形多边形(圆形面片的多边形近似值)。在

import matplotlib.pyplot as plt
from matplotlib.patches import CirclePolygon

circle = CirclePolygon((0, 0), radius = 0.75, fc = 'y')
plt.gca().add_patch(circle)
plt.axis('scaled')
plt.show()

对于上面的代码,我有下面的输出:
CirclePolygon

我需要所有的点在一起形成一个圆多边形。如何做到这一点?在


Tags: 代码fromimportmatplotlibasplt圆形多边形
1条回答
网友
1楼 · 发布于 2024-09-30 18:22:05

多边形基于路径。您可以通过circle.get_path()获得此路径。您对该路径的vertices感兴趣。 最后,需要根据多边形的变换对它们进行变换。在

import matplotlib.pyplot as plt
from matplotlib.patches import CirclePolygon

circle = CirclePolygon((0, 0), radius = 0.75, fc = 'y')
plt.gca().add_patch(circle)

verts = circle.get_path().vertices
trans = circle.get_patch_transform()
points = trans.transform(verts)
print(points)

plt.plot(points[:,0],points[:,1])
plt.axis('scaled')
plt.show()

蓝线是由此得到的点的图。在

enter image description here

相关问题 更多 >