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

Skip to content

Commit 6462a01

Browse files
authored
Merge pull request #25346 from rcomer/text-wrap
FIX: use wrapped text in Text._get_layout
2 parents fbe7a44 + 790bcc2 commit 6462a01

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,22 @@ def test_wrap():
701701
'times.')
702702

703703

704+
def test_get_window_extent_wrapped():
705+
# Test that a long title that wraps to two lines has the same vertical
706+
# extent as an explicit two line title.
707+
708+
fig1 = plt.figure(figsize=(3, 3))
709+
fig1.suptitle("suptitle that is clearly too long in this case", wrap=True)
710+
window_extent_test = fig1._suptitle.get_window_extent()
711+
712+
fig2 = plt.figure(figsize=(3, 3))
713+
fig2.suptitle("suptitle that is clearly\ntoo long in this case")
714+
window_extent_ref = fig2._suptitle.get_window_extent()
715+
716+
assert window_extent_test.y0 == window_extent_ref.y0
717+
assert window_extent_test.y1 == window_extent_ref.y1
718+
719+
704720
def test_long_word_wrap():
705721
fig = plt.figure(figsize=(6, 4))
706722
text = fig.text(9.5, 8, 'Alonglineoftexttowrap', wrap=True)

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def _get_layout(self, renderer):
367367
of a rotated text when necessary.
368368
"""
369369
thisx, thisy = 0.0, 0.0
370-
lines = self.get_text().split("\n") # Ensures lines is not empty.
370+
lines = self._get_wrapped_text().split("\n") # Ensures lines is not empty.
371371

372372
ws = []
373373
hs = []

0 commit comments

Comments
 (0)