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

Skip to content

Commit 0d45900

Browse files
authored
Merge pull request #26304 from meeseeksmachine/auto-backport-of-pr-26300-on-v3.7.x
Backport PR #26300 on branch v3.7.x (FIX: do not warn when calling tight_layout multiple times)
2 parents d67bec2 + 602c2e9 commit 0d45900

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,14 +3536,14 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
35363536
# note that here we do not permanently set the figures engine to
35373537
# tight_layout but rather just perform the layout in place and remove
35383538
# any previous engines.
3539-
engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad,
3540-
rect=rect)
3539+
engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
35413540
try:
35423541
previous_engine = self.get_layout_engine()
35433542
self.set_layout_engine(engine)
35443543
engine.execute(self)
3545-
if not isinstance(previous_engine, TightLayoutEngine) \
3546-
and previous_engine is not None:
3544+
if previous_engine is not None and not isinstance(
3545+
previous_engine, (TightLayoutEngine, PlaceHolderLayoutEngine)
3546+
):
35473547
_api.warn_external('The figure layout has changed to tight')
35483548
finally:
35493549
self.set_layout_engine('none')

lib/matplotlib/tests/test_figure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@ def test_layout_change_warning(layout):
641641
plt.tight_layout()
642642

643643

644+
def test_repeated_tightlayout():
645+
fig = Figure()
646+
fig.tight_layout()
647+
# subsequent calls should not warn
648+
fig.tight_layout()
649+
fig.tight_layout()
650+
651+
644652
@check_figures_equal(extensions=["png", "pdf"])
645653
def test_add_artist(fig_test, fig_ref):
646654
fig_test.dpi = 100

0 commit comments

Comments
 (0)