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

Skip to content

FIX: do not warn when calling tight_layout multiple times #26300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2023
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 @@ -3522,14 +3522,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 @@ -701,6 +701,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