Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the coordinates from CirclePolygon in matplotlib.patches

I have the following code, which generates a circle polygon (A polygon-approximation of a circle patch.) using 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()

For the code above, I have the output given below:
CirclePolygon

I need all the points that are together forming the circle polygon. How can this be achieved?

like image 468
Kartheek Palepu Avatar asked Oct 11 '25 18:10

Kartheek Palepu


1 Answers

The Polygon is based on a path. You may get this path via circle.get_path(). You're interested in the vertices of this path. Finally you need to transform them according to the Polygon's transform.

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()

The blue line is a plot of the thus obtained points.

enter image description here


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!