Skip to content

Add optional axes-aware text wrapping#31633

Open
codegnan-dm wants to merge 5 commits intomatplotlib:mainfrom
codegnan-dm:fix/text-wrap-axes-boundary
Open

Add optional axes-aware text wrapping#31633
codegnan-dm wants to merge 5 commits intomatplotlib:mainfrom
codegnan-dm:fix/text-wrap-axes-boundary

Conversation

@codegnan-dm
Copy link
Copy Markdown

@codegnan-dm codegnan-dm commented May 8, 2026

Screenshot 2026-05-08 111451 Screenshot 2026-05-08 112557 Fixes #31635

Summary

When wrap=True is used on text inside an axes, the wrapping incorrectly
used the figure boundary instead of the axes boundary. This caused text
to overflow outside its axes into adjacent axes or outside the figure.

This fix checks whether the text object belongs to an axes, and if so,
uses the axes boundary for wrapping. Otherwise it falls back to the
figure boundary.

Fixes

Closes #[correct issue number here]

PR Checklist

  • Has pytest style unit tests
  • Code is well-commented
  • New features/changed behavior has been documented

AI Disclosure

This PR was developed with AI assistance for guidance on code location
and fix approach. The implementation, testing, and verification were
done manually.

@codegnan-dm codegnan-dm force-pushed the fix/text-wrap-axes-boundary branch from 14d1973 to d3cadcb Compare May 8, 2026 06:13
@codegnan-dm codegnan-dm changed the title Fix text wrapping to use axes boundary instead of figure boundary\ Fix text wrapping to use axes boundary instead of figure boundary May 8, 2026
@codegnan-dm codegnan-dm force-pushed the fix/text-wrap-axes-boundary branch from d3cadcb to b665ac4 Compare May 8, 2026 06:17
@rcomer
Copy link
Copy Markdown
Member

rcomer commented May 8, 2026

Thank you for your willingness to contribute. Did you intend to link a different issue? The one you linked is not about text in an axes.

Also please fill out the PR summary using our template and ensure the tests pass.

@rcomer rcomer added status: needs clarification Issues that need more information to resolve. status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks labels May 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

⏰ This pull request might be automatically closed in two weeks from now.

Thank you for your contribution to Matplotlib and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity standards needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep Matplotlib maintainable.

Matplotlib maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬

To increase the chance of a productive review:

As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a new contributor, or do not know how to fulfill these requirements, we recommend that you familiarize yourself with Matplotlib's development conventions or engage with the community via our Discourse or one of our meetings before submitting code.

If you substantially improve this PR within two weeks, leave a comment and a team member may remove the status: autoclose candidate label and the PR stays open. Cosmetic changes or incomplete fixes will not be sufficient. Maintainers will assess improvements on their own schedule. Please do not ping (@) maintainers.

@codegnan-dm
Copy link
Copy Markdown
Author

Thanks for the feedback.

I’ll update the PR summary/template and verify whether the linked issue is correct.

I’ll also investigate the failing tests and push fixes shortly.

@codegnan-dm
Copy link
Copy Markdown
Author

@rcomer Thank you for the clarification. I have opened a new issue #31635
which correctly describes the bug this PR fixes — when ax.text()
is used with wrap=True inside an axes, wrapping incorrectly uses
the figure boundary instead of the axes boundary, causing text to
overflow outside the axes. I have updated the PR description accordingly.

@codegnan-dm
Copy link
Copy Markdown
Author

The rstcheck precommit failure is a pre-existing issue in the repo —
doc/users/getting_started/index.rst references a file
/install/quick_install.inc.rst that does not exist. This is unrelated
to my changes and can be verified by checking the same error on other
recent PRs.

@codegnan-dm
Copy link
Copy Markdown
Author

The AppVeyor Windows CI failure is an infrastructure issue — micromamba
failed to parse its history file and crashed during dependency installation
(line 1929: Command exited with code 1). Tests never ran as a result.
This is unrelated to my changes.

@codegnan-dm codegnan-dm changed the title Fix text wrapping to use axes boundary instead of figure boundary Add optional axes-aware text wrapping May 8, 2026
@codegnan-dm
Copy link
Copy Markdown
Author

@rcomer Thanks for the clarification.

I understand the current behavior is consistent with the documented implementation of set_wrap.

I’ve updated the PR to frame this as an optional axes-aware wrapping enhancement while preserving existing default behavior for backward compatibility.

@rcomer
Copy link
Copy Markdown
Member

rcomer commented May 8, 2026

@codegnan-dm before taking this PR further, please could you open an issue feature request describing your use case? I.e., what do you use Matplotlib for and why do you want this?

@rcomer rcomer removed the status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks label May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs clarification Issues that need more information to resolve. topic: text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Support wrapping text relative to axes boundaries

2 participants