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

Skip to content

Commit f7574a4

Browse files
committed
FIX: do not warn when calling tight_layout multiple times
Closes #26290
1 parent 02d2e13 commit f7574a4

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
@@ -3522,14 +3522,14 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
35223522
# note that here we do not permanently set the figures engine to
35233523
# tight_layout but rather just perform the layout in place and remove
35243524
# any previous engines.
3525-
engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad,
3526-
rect=rect)
3525+
engine = TightLayoutEngine(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
35273526
try:
35283527
previous_engine = self.get_layout_engine()
35293528
self.set_layout_engine(engine)
35303529
engine.execute(self)
3531-
if not isinstance(previous_engine, TightLayoutEngine) \
3532-
and previous_engine is not None:
3530+
if previous_engine is not None and not isinstance(
3531+
previous_engine, (TightLayoutEngine, PlaceHolderLayoutEngine)
3532+
):
35333533
_api.warn_external('The figure layout has changed to tight')
35343534
finally:
35353535
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
@@ -701,6 +701,14 @@ def test_layout_change_warning(layout):
701701
plt.tight_layout()
702702

703703

704+
def test_repeated_tightlayout():
705+
fig = Figure()
706+
fig.tight_layout()
707+
# subsequent calls should not warn
708+
fig.tight_layout()
709+
fig.tight_layout()
710+
711+
704712
@check_figures_equal(extensions=["png", "pdf"])
705713
def test_add_artist(fig_test, fig_ref):
706714
fig_test.dpi = 100

0 commit comments

Comments
 (0)