Python, Matplotlib; drawing a partial circle

Viewed 28

I can draw a full circle like so:

plt.figure()
ax = plt.gca()

# Make the circle patch and add to the figure
circle = plt.Circle((1, 0), 1, color='r', fill=None)
ax.add_patch(circle)
    
# Make it a perfect circle by making it a perfect square box
ax.set_aspect('equal', adjustable='box')
    
# Set axis so it's visible 
plt.xlim([-0.5,2.5])    
plt.ylim([-1.5, 1.5])  

enter image description here

So far so good. But, what I only want a portion of the circle? For example, something that looks like this.

enter image description here

I could just plot something on top of it with the same color as the background, but that seems a little hacky. Is there a better way?

1 Answers

What about using an Arc?

from matplotlib.patches import Arc
radius = 1
arc = Arc((1, 0), radius*2, radius*2, color='b', theta1=90, theta2=360)
ax.add_patch(arc)

output:

enter image description here

output on top of the original circle:

enter image description here

Related