diff --git a/lib/matplotlib/_tight_layout.py b/lib/matplotlib/_tight_layout.py index 7776e890cbe3..e99ba49bd284 100644 --- a/lib/matplotlib/_tight_layout.py +++ b/lib/matplotlib/_tight_layout.py @@ -226,7 +226,10 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, ss_to_subplots = {ss: [] for ss in subplotspec_list} for ax, ss in zip(axes_list, subplotspec_list): ss_to_subplots[ss].append(ax) - ss_to_subplots.pop(None, None) # Skip subplotspec == None. + if ss_to_subplots.pop(None, None): + _api.warn_external( + "This figure includes Axes that are not compatible with " + "tight_layout, so results might be incorrect.") if not ss_to_subplots: return {} subplot_list = list(ss_to_subplots.values()) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index e015d0ec94bb..b1e251940210 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -3424,12 +3424,6 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None): .Figure.set_layout_engine .pyplot.tight_layout """ - from ._tight_layout import get_subplotspec_list - subplotspec_list = get_subplotspec_list(self.axes) - if None in subplotspec_list: - _api.warn_external("This figure includes Axes that are not " - "compatible with tight_layout, so results " - "might be incorrect.") # 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. diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index 06dd3f19f68a..3a019bc62f6a 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -467,20 +467,12 @@ def tight_layout(self, figure, renderer=None, coordinates that the whole subplots area (including labels) will fit into. Default (None) is the whole figure. """ - - subplotspec_list = _tight_layout.get_subplotspec_list( - figure.axes, grid_spec=self) - if None in subplotspec_list: - _api.warn_external("This figure includes Axes that are not " - "compatible with tight_layout, so results " - "might be incorrect.") - if renderer is None: renderer = figure._get_renderer() - kwargs = _tight_layout.get_tight_layout_figure( - figure, figure.axes, subplotspec_list, renderer, - pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) + figure, figure.axes, + _tight_layout.get_subplotspec_list(figure.axes, grid_spec=self), + renderer, pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) if kwargs: self.update(**kwargs) diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index 56e82b5699c7..4f3e7a9ce95c 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -17,7 +17,6 @@ from contextlib import nullcontext import matplotlib as mpl -import matplotlib._api as _api from matplotlib._constrained_layout import do_constrained_layout from matplotlib._tight_layout import (get_subplotspec_list, @@ -170,15 +169,10 @@ def execute(self, fig): See also: `.figure.Figure.tight_layout` and `.pyplot.tight_layout`. """ info = self._params - subplotspec_list = get_subplotspec_list(fig.axes) - if None in subplotspec_list: - _api.warn_external("This figure includes Axes that are not " - "compatible with tight_layout, so results " - "might be incorrect.") renderer = fig._get_renderer() with getattr(renderer, "_draw_disabled", nullcontext)(): kwargs = get_tight_layout_figure( - fig, fig.axes, subplotspec_list, renderer, + fig, fig.axes, get_subplotspec_list(fig.axes), renderer, pad=info['pad'], h_pad=info['h_pad'], w_pad=info['w_pad'], rect=info['rect']) if kwargs: