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
8 changes: 4 additions & 4 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3536,14 +3536,14 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
# note that here we do not permanently set the figures engine to
# tight_layout but rather just perform the layout in place and remove
# any previous engines.
engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad,
rect=rect)
engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
try:
previous_engine = self.get_layout_engine()
self.set_layout_engine(engine)
engine.execute(self)
if not isinstance(previous_engine, TightLayoutEngine) \
and previous_engine is not None:
if previous_engine is not None and not isinstance(
previous_engine, (TightLayoutEngine, PlaceHolderLayoutEngine)
):
_api.warn_external('The figure layout has changed to tight')
finally:
self.set_layout_engine('none')
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,14 @@ def test_layout_change_warning(layout):
plt.tight_layout()


def test_repeated_tightlayout():
fig = Figure()
fig.tight_layout()
# subsequent calls should not warn
fig.tight_layout()
fig.tight_layout()


@check_figures_equal(extensions=["png", "pdf"])
def test_add_artist(fig_test, fig_ref):
fig_test.dpi = 100
Expand Down