Remove mpl.text._get_textbox.#31179
Open
anntzer wants to merge 1 commit intomatplotlib:text-overhaulfrom
Open
Conversation
Consider a multiline Text object with nonzero rotation. Text._get_layout performs the layouting of the individual lines. Previously, it would return (among other things) the axes-aligned bbox of the whole Text (which can be much bigger than the rotated bbox), as well as the metrics of each individual line. mpl.text._get_layout would then take these individual metrics and unrotate their positions (to horizontal lines) to compute the size of the *rotated* bbox of the text (and its position as well); this is used solely when drawing a (text-aligned) bbox around the text (`plt.text(..., bbox=...)`). The back-and-forth rotation seems a bit complicated; one can instead simply return the relevant info in Text._get_layout as well: the rotated bbox size is already available (in the variable previously named `corners_horiz`), and getting its position is also simple. Do that, and get rid of mpl.text._get_textbox (and also adjust the callers of Text._get_layout accordingly). Also add some additional drive-by reformatting of Text._get_layout.
timhoffm
reviewed
Feb 20, 2026
timhoffm
approved these changes
Feb 20, 2026
Member
timhoffm
left a comment
There was a problem hiding this comment.
It feels a bit weird that we use the one or other set of return values exclusively, I.e.
bbox, info, _ and _, _, (…) but that’s maybe as it is. In theory this could be two separate functions, but the implementation overlap is large. Maybe there’s a clearer way (I haven’t dug deep to see whether e.g. one could build on the other), but it’s good enough for now.
Contributor
Author
|
You would need to have another helper function that returns some common info that allows computing the end results, but disentangling the calculations would require a bit more work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consider a multiline Text object with nonzero rotation. Text._get_layout performs the layouting of the individual lines. Previously, it would return (among other things) the axes-aligned bbox of the whole Text (which can be much bigger than the rotated bbox), as well as the metrics of each individual line. mpl.text._get_layout would then take these individual metrics and unrotate their positions (to horizontal lines) to compute the size of the rotated bbox of the text (and its position as well); this is used solely when drawing a (text-aligned) bbox around the text (
plt.text(..., bbox=...)).The back-and-forth rotation seems a bit complicated; one can instead simply return the relevant info in Text._get_layout as well: the rotated bbox size is already available (in the variable previously named
corners_horiz), and getting its position is also simple. Do that, and get rid of mpl.text._get_textbox (and also adjust the callers of Text._get_layout accordingly). Also add some additional drive-by reformatting of Text._get_layout.Note: This would result in merge conflicts with @scottshambaugh's #31001, but the two PRs target different branches (this one is on text-overhaul because it goes on top of the "fix ascent/height confusion" PR). I don't mind rebasing this on top of #31001 if (the text-related parts of) that one also get retargeted to text-overhaul.
PR summary
PR checklist