Open
Description
Bug summary
In matplotlib 3.9.1, the clip_path
and clip_bbox
arguments of annotate
do not properly clip the annotation.
The code example below worked as expected in 3.8.
Code for reproduction
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox, TransformedBbox
fig, ax = plt.subplots()
rect = ax.axvspan(0.5, 0.55, 0, 1)
transform = ax.get_xaxis_transform()
bbox = Bbox.from_extents(0.5, 0, 0.55, 1)
tbbox = TransformedBbox(bbox, transform)
text_kw= dict()
text_kw.setdefault("va", "top")
text_kw.setdefault("clip_on", True)
text_kw.setdefault("bbox", dict(boxstyle="round", facecolor="white"))
ann = ax.annotate(
"Annotation",
xy=(0.5, 1),
xytext=(8, -10),
textcoords="offset points",
clip_path=rect,
clip_box=tbbox,
**text_kw,
)
ax.set(xlim=[0, 1])
Actual outcome
In matplotlib 3.9.1. Note that the annotation is not clipped.
Expected outcome
Generated with matplotlib 3.8.1; the annotation is properly clipped.
Additional information
No response
Operating system
n/a
Matplotlib Version
3.9.1
Matplotlib Backend
'module://matplotlib_inline.backend_inline'
Python version
many (3.8 to 3.12)
Jupyter version
n/a
Installation
conda
Metadata
Metadata
Assignees
Labels
No labels