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

Skip to content

Commit 1c8975a

Browse files
authored
Merge pull request #25964 from StefRe/fix/get_constrained_layout_pads
Fix get_constrained_layout_pads
2 parents 6a323c0 + b45d2c4 commit 1c8975a

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ def get_constrained_layout_pads(self, relative=False):
28722872
"""
28732873
if not isinstance(self.get_layout_engine(), ConstrainedLayoutEngine):
28742874
return None, None, None, None
2875-
info = self.get_layout_engine().get_info()
2875+
info = self.get_layout_engine().get()
28762876
w_pad = info['w_pad']
28772877
h_pad = info['h_pad']
28782878
wspace = info['wspace']

lib/matplotlib/layout_engine.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def __init__(self, **kwargs):
6464
self._params = {}
6565

6666
def set(self, **kwargs):
67+
"""
68+
Set the parameters for the layout engine.
69+
"""
6770
raise NotImplementedError
6871

6972
@property
@@ -120,6 +123,9 @@ def __init__(self, adjust_compatible, colorbar_gridspec, **kwargs):
120123
super().__init__(**kwargs)
121124

122125
def execute(self, fig):
126+
"""
127+
Do nothing.
128+
"""
123129
return
124130

125131

@@ -138,7 +144,7 @@ def __init__(self, *, pad=1.08, h_pad=None, w_pad=None,
138144
139145
Parameters
140146
----------
141-
pad : float, 1.08
147+
pad : float, default: 1.08
142148
Padding between the figure edge and the edges of subplots, as a
143149
fraction of the font size.
144150
h_pad, w_pad : float
@@ -182,6 +188,21 @@ def execute(self, fig):
182188
fig.subplots_adjust(**kwargs)
183189

184190
def set(self, *, pad=None, w_pad=None, h_pad=None, rect=None):
191+
"""
192+
Set the pads for tight_layout.
193+
194+
Parameters
195+
----------
196+
pad : float
197+
Padding between the figure edge and the edges of subplots, as a
198+
fraction of the font size.
199+
w_pad, h_pad : float
200+
Padding (width/height) between edges of adjacent subplots.
201+
Defaults to *pad*.
202+
rect : tuple (left, bottom, right, top)
203+
rectangle in normalized figure coordinates that the subplots
204+
(including labels) will fit into.
205+
"""
185206
for td in self.set.__kwdefaults__:
186207
if locals()[td] is not None:
187208
self._params[td] = locals()[td]

lib/matplotlib/tests/test_figure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,3 +1603,11 @@ def test_savefig_metadata(fmt):
16031603
def test_savefig_metadata_error(fmt):
16041604
with pytest.raises(ValueError, match="metadata not supported"):
16051605
Figure().savefig(io.BytesIO(), format=fmt, metadata={})
1606+
1607+
1608+
def test_get_constrained_layout_pads():
1609+
params = {'w_pad': 0.01, 'h_pad': 0.02, 'wspace': 0.03, 'hspace': 0.04}
1610+
expected = tuple([*params.values()])
1611+
fig = plt.figure(layout=mpl.layout_engine.ConstrainedLayoutEngine(**params))
1612+
with pytest.warns(PendingDeprecationWarning, match="will be deprecated"):
1613+
assert fig.get_constrained_layout_pads() == expected

0 commit comments

Comments
 (0)