Skip to content
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
2 changes: 2 additions & 0 deletions doc/users/next_whats_new/2020-04-22-suptitle-tl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tight_layout now supports suptitle
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_tightlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,11 @@ def test_collapsed():
# test that passing a rect doesn't crash...
with pytest.warns(UserWarning):
plt.tight_layout(rect=[0, 0, 0.8, 0.8])


def test_suptitle():
fig, ax = plt.subplots(tight_layout=True)
st = fig.suptitle("foo")
t = ax.set_title("bar")
fig.canvas.draw()
assert st.get_window_extent().y0 > t.get_window_extent().y1
6 changes: 6 additions & 0 deletions lib/matplotlib/tight_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,15 @@ def auto_adjust_subplotpars(
if not margin_top:
margin_top = (max(vspaces[0, :].max(), 0)
+ pad_inches / fig_height_inch)
suptitle = fig._suptitle
if suptitle and suptitle.get_in_layout():
rel_suptitle_height = fig.transFigure.inverted().transform_bbox(
suptitle.get_window_extent(renderer)).height
margin_top += rel_suptitle_height + pad_inches / fig_height_inch
if not margin_bottom:
margin_bottom = (max(vspaces[-1, :].max(), 0)
+ pad_inches / fig_height_inch)

if margin_left + margin_right >= 1:
cbook._warn_external('Tight layout not applied. The left and right '
'margins cannot be made large enough to '
Expand Down