Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b55f8c5

Browse filesBrowse files
authored
Merge pull request #17219 from anntzer/tls
ENH: Add support for suptitle() in tight_layout().
2 parents c5386a3 + 0f26a46 commit b55f8c5
Copy full SHA for b55f8c5

File tree

Expand file treeCollapse file tree

3 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-0
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tight_layout now supports suptitle
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

‎lib/matplotlib/tests/test_tightlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_tightlayout.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,11 @@ def test_collapsed():
308308
# test that passing a rect doesn't crash...
309309
with pytest.warns(UserWarning):
310310
plt.tight_layout(rect=[0, 0, 0.8, 0.8])
311+
312+
313+
def test_suptitle():
314+
fig, ax = plt.subplots(tight_layout=True)
315+
st = fig.suptitle("foo")
316+
t = ax.set_title("bar")
317+
fig.canvas.draw()
318+
assert st.get_window_extent().y0 > t.get_window_extent().y1

‎lib/matplotlib/tight_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tight_layout.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,15 @@ def auto_adjust_subplotpars(
107107
if not margin_top:
108108
margin_top = (max(vspaces[0, :].max(), 0)
109109
+ pad_inches / fig_height_inch)
110+
suptitle = fig._suptitle
111+
if suptitle and suptitle.get_in_layout():
112+
rel_suptitle_height = fig.transFigure.inverted().transform_bbox(
113+
suptitle.get_window_extent(renderer)).height
114+
margin_top += rel_suptitle_height + pad_inches / fig_height_inch
110115
if not margin_bottom:
111116
margin_bottom = (max(vspaces[-1, :].max(), 0)
112117
+ pad_inches / fig_height_inch)
118+
113119
if margin_left + margin_right >= 1:
114120
cbook._warn_external('Tight layout not applied. The left and right '
115121
'margins cannot be made large enough to '

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.