Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: use wrapped text in Text._get_layout #25346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,22 @@ def test_wrap():
'times.')


def test_get_window_extent_wrapped():
# Test that a long title that wraps to two lines has the same vertical
# extent as an explicit two line title.

fig1 = plt.figure(figsize=(3, 3))
fig1.suptitle("suptitle that is clearly too long in this case", wrap=True)
window_extent_test = fig1._suptitle.get_window_extent()

fig2 = plt.figure(figsize=(3, 3))
fig2.suptitle("suptitle that is clearly\ntoo long in this case")
window_extent_ref = fig2._suptitle.get_window_extent()

assert window_extent_test.y0 == window_extent_ref.y0
assert window_extent_test.y1 == window_extent_ref.y1


def test_long_word_wrap():
fig = plt.figure(figsize=(6, 4))
text = fig.text(9.5, 8, 'Alonglineoftexttowrap', wrap=True)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _get_layout(self, renderer):
of a rotated text when necessary.
"""
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
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
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?


ws = []
hs = []
Expand Down