Skip to content

ENH: Support wrap='axes' and wrap='figure' for axes-aware text wrapping#31716

Open
codegnan-dm wants to merge 1 commit into
matplotlib:mainfrom
codegnan-dm:fix/axes-aware-wrap-v2
Open

ENH: Support wrap='axes' and wrap='figure' for axes-aware text wrapping#31716
codegnan-dm wants to merge 1 commit into
matplotlib:mainfrom
codegnan-dm:fix/axes-aware-wrap-v2

Conversation

@codegnan-dm
Copy link
Copy Markdown

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

Closes #31655
Supersedes #31633

Summary

Extends the wrap parameter of Text.set_wrap() to accept string
values in addition to bool:

  • wrap=True or wrap='figure': wrap to figure boundary (default,
    fully backward compatible)
  • wrap='axes': wrap to axes boundary when text is inside an axes

This design was discussed and agreed upon in issue #31655 by
@rcomer, @timhoffm, and @story645.

PR Checklist

  • Has pytest style unit tests
  • Code is well-commented
  • New features/changed behavior has been documented in the docstring
  • All tests pass (except pre-existing infrastructure failures)
  • Conforms to the coding style of the project

Testing

Usage example:

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 4))

# New: wrap to axes boundary
ax1.text(0.05, 0.5, "Long text that wraps within axes", 
         wrap='axes', transform=ax1.transAxes)

# Existing behavior unchanged: wrap to figure boundary  
ax1.text(0.05, 0.3, "Long text that wraps to figure", 
         wrap=True, transform=ax1.transAxes)

AI Disclosure

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

@rcomer
Copy link
Copy Markdown
Member

rcomer commented May 20, 2026

Please use the PR checklist provided in the PR template. It includes some items that are required and that you have missed here.

@rcomer rcomer added the status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks label May 20, 2026
@github-actions
Copy link
Copy Markdown

⏰ 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.

@rcomer
Copy link
Copy Markdown
Member

rcomer commented May 20, 2026

I added the “autoclose” because its comment provides useful links about what you need to do. Two weeks may not be long enough for this case so we can review as needed.

@codegnan-dm
Copy link
Copy Markdown
Author

@rcomer I have updated the PR description with the full checklist
from the template. Please let me know if anything else is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks topic: text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: Optional axes-aware text wrapping for wrap=True

2 participants