diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 39517e14d0e3..08bb483d606b 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2872,7 +2872,7 @@ def get_constrained_layout_pads(self, relative=False): """ if not isinstance(self.get_layout_engine(), ConstrainedLayoutEngine): return None, None, None, None - info = self.get_layout_engine().get_info() + info = self.get_layout_engine().get() w_pad = info['w_pad'] h_pad = info['h_pad'] wspace = info['wspace'] diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index 1989f89684f1..d751059f4e09 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -64,6 +64,9 @@ def __init__(self, **kwargs): self._params = {} def set(self, **kwargs): + """ + Set the parameters for the layout engine. + """ raise NotImplementedError @property @@ -120,6 +123,9 @@ def __init__(self, adjust_compatible, colorbar_gridspec, **kwargs): super().__init__(**kwargs) def execute(self, fig): + """ + Do nothing. + """ return @@ -138,7 +144,7 @@ def __init__(self, *, pad=1.08, h_pad=None, w_pad=None, Parameters ---------- - pad : float, 1.08 + pad : float, default: 1.08 Padding between the figure edge and the edges of subplots, as a fraction of the font size. h_pad, w_pad : float @@ -182,6 +188,21 @@ def execute(self, fig): fig.subplots_adjust(**kwargs) def set(self, *, pad=None, w_pad=None, h_pad=None, rect=None): + """ + Set the pads for tight_layout. + + Parameters + ---------- + pad : float + Padding between the figure edge and the edges of subplots, as a + fraction of the font size. + w_pad, h_pad : float + Padding (width/height) between edges of adjacent subplots. + Defaults to *pad*. + rect : tuple (left, bottom, right, top) + rectangle in normalized figure coordinates that the subplots + (including labels) will fit into. + """ for td in self.set.__kwdefaults__: if locals()[td] is not None: self._params[td] = locals()[td] diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index a795a3fbe3f5..474331bf9149 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -1603,3 +1603,11 @@ def test_savefig_metadata(fmt): def test_savefig_metadata_error(fmt): with pytest.raises(ValueError, match="metadata not supported"): Figure().savefig(io.BytesIO(), format=fmt, metadata={}) + + +def test_get_constrained_layout_pads(): + params = {'w_pad': 0.01, 'h_pad': 0.02, 'wspace': 0.03, 'hspace': 0.04} + expected = tuple([*params.values()]) + fig = plt.figure(layout=mpl.layout_engine.ConstrainedLayoutEngine(**params)) + with pytest.warns(PendingDeprecationWarning, match="will be deprecated"): + assert fig.get_constrained_layout_pads() == expected