Skip to content

FIX: use wrapped text in Text._get_layout#25346

Merged
jklymak merged 1 commit into
matplotlib:mainfrom
rcomer:text-wrap
Feb 28, 2023
Merged

FIX: use wrapped text in Text._get_layout#25346
jklymak merged 1 commit into
matplotlib:mainfrom
rcomer:text-wrap

Conversation

@rcomer
Copy link
Copy Markdown
Member

@rcomer rcomer commented Feb 28, 2023

PR Summary

Fixes #25336.

Constrained layout here relies on Text.get_tightbbox, which calls Text.get_window_extent, which calls Text._get_layout. The example code in the issue now produces:

test

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@rcomer rcomer added topic: text topic: geometry manager LayoutEngine, Constrained layout, Tight layout PR: bugfix Pull requests that fix identified bugs labels Feb 28, 2023
Comment thread lib/matplotlib/text.py
"""
thisx, thisy = 0.0, 0.0
lines = self.get_text().split("\n") # Ensures lines is not empty.
lines = self._get_wrapped_text().split("\n") # Ensures lines is not empty.
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.

Do you understand what the comment is about?

Copy link
Copy Markdown
Member Author

@rcomer rcomer Feb 28, 2023

Choose a reason for hiding this comment

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

Not completely, though I can see that there are a bunch of necessary variables defined in the loop at lines 383-414, which would not exist if lines was empty. So maybe this is just providing reassurance for that?

@jklymak jklymak merged commit 6462a01 into matplotlib:main Feb 28, 2023
@rcomer
Copy link
Copy Markdown
Member Author

rcomer commented Feb 28, 2023

Thanks @timhoffm @jklymak

@rcomer rcomer deleted the text-wrap branch February 28, 2023 18:18
@rcomer rcomer added this to the v3.7.1 milestone Feb 28, 2023
@rcomer
Copy link
Copy Markdown
Member Author

rcomer commented Feb 28, 2023

@meeseeksdev backport to v3.7.x

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 28, 2023
oscargus added a commit that referenced this pull request Feb 28, 2023
…346-on-v3.7.x

Backport PR #25346 on branch v3.7.x (FIX: use wrapped text in Text._get_layout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bugfix Pull requests that fix identified bugs topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: constrained layout with wrapped titles

3 participants