Skip to content

Fix constrainedlayout figartists#31425

Draft
Arnav-xD wants to merge 2 commits intomatplotlib:mainfrom
Arnav-xD:fix-constrainedlayout-figartists
Draft

Fix constrainedlayout figartists#31425
Arnav-xD wants to merge 2 commits intomatplotlib:mainfrom
Arnav-xD:fix-constrainedlayout-figartists

Conversation

@Arnav-xD
Copy link
Copy Markdown

Constrained layout currently does not account for figure-level artists such as fig.text() and fig.legend(), which can lead to overlaps or clipping of drawings or graphs.
This patch includes these artists in margin calculations using their tight bounding boxes, respecting visibility and get_in_layout().
A test is added to verify that figure-level text does not overlap axes.

@github-actions
Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@github-actions github-actions bot added first-contribution topic: geometry manager LayoutEngine, Constrained layout, Tight layout and removed first-contribution labels Mar 30, 2026
# === NEW: handle figure-level texts ===
inv_trans_fig = fig.transFigure.inverted().transform_bbox

for text in fig.texts:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test locally on a minimal script that shows the before and after before pushing to GitHub. There is no way this worked locally with the typo here and you can see you are failing all the tests. I'll move this to draft

Copy link
Copy Markdown
Author

@Arnav-xD Arnav-xD Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out, I missed testing locally and introduced a typo. I'm trying to fix the issue and verify the behavior with a minimal example. I'll keep iterating if anything else needs adjustment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share the minimal example and before and after in the description of the PR? Also you appear to not have pushed any changes to the Github yet

@jklymak jklymak marked this pull request as draft March 30, 2026 15:52
@melissawm melissawm moved this to Waiting for author in First Time Contributors Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-contribution topic: geometry manager LayoutEngine, Constrained layout, Tight layout

Projects

Status: Waiting for author

Development

Successfully merging this pull request may close these issues.

3 participants