I'm attempting to clip shapes like circles and ellipses using clipping in Matplotlib, but there must be something I am missing.. Why doesn't this clip the circle in half?:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
from matplotlib.transforms import Bbox
clip_box = Bbox(((-2,-2),(2,0)))
circle = Circle((0,0),1,clip_box=clip_box,clip_on=True)
plt.axes().add_artist(circle)
plt.axis('equal')
plt.axis((-2,2,-2,2))
plt.show()
I do not know why your code does not work, however, the following snippet works as you expect.
From my undestanding, clip_on is not related to applying a given clipping to a shape but wether the shape should clip in the display area.
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, Rectangle
rect = Rectangle((-2,-2),4,2, facecolor="none", edgecolor="none")
circle = Circle((0,0),1)
plt.axes().add_artist(rect)
plt.axes().add_artist(circle)
circle.set_clip_path(rect)
plt.axis('equal')
plt.axis((-2,2,-2,2))
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With