FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: PaddedBox not working · Issue #24620 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: PaddedBox not working #24620

Open
Open

Description

Bug summary

PaddedBox https://matplotlib.org/stable/api/offsetbox_api.html#matplotlib.offsetbox.PaddedBox doesn't look like it is working properly.

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.offsetbox import PaddedBox, AnchoredText

fig, ax = plt.subplots()

at = AnchoredText("foo",  'upper left')
pb = PaddedBox(at, pad=1, patch_attrs={'facecolor' : 'r'}, draw_frame=True)

ax.add_artist(pb)
fig.show()

Actual outcome

Expected outcome

Red box is at same location as text.

Additional information

It seems like the sizing is working OK (using a longer string will change the size accordingly), but that the positioning is not working.

Also, not passing pad leads to an error, so it should probably be 0. as default rather than None.

Operating system

No response

Matplotlib Version

main

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

Activity

  1. leejjoon commented on Dec 7, 2022

    Contributor

    I do not remember the details but my recollection is that AnchoredText (and its siblings) is meant to be a top level object in the offsetbox chain. So, PaddedBox (likely any offsetbox) is not supposed to have any anchored children.

    Here is working example, that uses AnchoredOffsetbox, instead.

    import matplotlib.pyplot as plt
    from matplotlib.offsetbox import (PaddedBox, AnchoredText,
                                      AnchoredOffsetbox, TextArea)
    
    fig, ax = plt.subplots()
    
    ta = TextArea("foo")
    pb = PaddedBox(ta, pad=5, patch_attrs={'facecolor' : 'r'}, draw_frame=True)
    ab = AnchoredOffsetbox('upper left', child=pb)
    
    ax.add_artist(ab)
    plt.show()

  2. oscargus commented on Dec 9, 2022

    MemberAuthor

    I guess that it may be good with some sort of clarification how the hierarchy of offset boxes works, so adding the doc label.

    If I understand it correctly, some, like TextArea and DrawingArea are the "base artists". These can be put in PaddedBox and Packers. Any of the earlier can then be put in Anchored*?

  3. leejjoon commented on Dec 9, 2022

    Contributor

    Correct. OffsetBox knows it size but not its position. Its parent should set its position at the drawing time. So, the top-most parent of offsetboxes should be Anchored* or AnnotationBbox that know how to position their children.

  4. github-actions commented on Feb 2, 2026

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  5. added
    keepItems to be ignored by the “Stale” Github Action
    on Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationkeepItems to be ignored by the “Stale” Github Actionstatus: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL