From 5e1c3089435bd7426b986a0dd80271d789783e1e Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Thu, 3 Nov 2022 11:24:27 -0500 Subject: [PATCH] Backport PR #24343: Emit "axes not compatible with tight_layout" in a single place. --- lib/matplotlib/_tight_layout.py | 5 ++++- lib/matplotlib/figure.py | 6 ------ lib/matplotlib/gridspec.py | 14 +++----------- lib/matplotlib/layout_engine.py | 8 +------- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/lib/matplotlib/_tight_layout.py b/lib/matplotlib/_tight_layout.py index 192c2dcfdcb9..0d138374acef 100644 --- a/lib/matplotlib/_tight_layout.py +++ b/lib/matplotlib/_tight_layout.py @@ -268,7 +268,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 e879549167cd..ce521fbfa9da 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -3429,12 +3429,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 2dc066adefa9..982ece3b36a3 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: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy