Skip to content

[Bug]: Annotation clip path / box regression in 3.9 #28717

Open
@bmcfee

Description

@bmcfee

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

image

In matplotlib 3.9.1. Note that the annotation is not clipped.

Expected outcome

image

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy