Skip to content

Commit 54e3f9a

Browse files
authored
Merge pull request #25975 from QuLogic/auto-backport-of-pr-25964-on-v3.7.x
Backport PR #25964 on branch v3.7.x (Fix get_constrained_layout_pads)
2 parents f37966a + 685c2ca commit 54e3f9a

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
@@ -2874,7 +2874,7 @@ def get_constrained_layout_pads(self, relative=False):
28742874
"""
28752875
if not isinstance(self.get_layout_engine(), ConstrainedLayoutEngine):
28762876
return None, None, None, None
2877-
info = self.get_layout_engine().get_info()
2877+
info = self.get_layout_engine().get()
28782878
w_pad = info['w_pad']
28792879
h_pad = info['h_pad']
28802880
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
@@ -121,6 +124,9 @@ def __init__(self, adjust_compatible, colorbar_gridspec, **kwargs):
121124
super().__init__(**kwargs)
122125

123126
def execute(self, fig):
127+
"""
128+
Do nothing.
129+
"""
124130
return
125131

126132

@@ -139,7 +145,7 @@ def __init__(self, *, pad=1.08, h_pad=None, w_pad=None,
139145
140146
Parameters
141147
----------
142-
pad : float, 1.08
148+
pad : float, default: 1.08
143149
Padding between the figure edge and the edges of subplots, as a
144150
fraction of the font size.
145151
h_pad, w_pad : float
@@ -183,6 +189,21 @@ def execute(self, fig):
183189
fig.subplots_adjust(**kwargs)
184190

185191
def set(self, *, pad=None, w_pad=None, h_pad=None, rect=None):
192+
"""
193+
Set the pads for tight_layout.
194+
195+
Parameters
196+
----------
197+
pad : float
198+
Padding between the figure edge and the edges of subplots, as a
199+
fraction of the font size.
200+
w_pad, h_pad : float
201+
Padding (width/height) between edges of adjacent subplots.
202+
Defaults to *pad*.
203+
rect : tuple (left, bottom, right, top)
204+
rectangle in normalized figure coordinates that the subplots
205+
(including labels) will fit into.
206+
"""
186207
for td in self.set.__kwdefaults__:
187208
if locals()[td] is not None:
188209
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
@@ -1529,3 +1529,11 @@ def test_gridspec_no_mutate_input():
15291529
plt.subplots(1, 2, width_ratios=[1, 2], gridspec_kw=gs)
15301530
assert gs == gs_orig
15311531
plt.subplot_mosaic('AB', width_ratios=[1, 2], gridspec_kw=gs)
1532+
1533+
1534+
def test_get_constrained_layout_pads():
1535+
params = {'w_pad': 0.01, 'h_pad': 0.02, 'wspace': 0.03, 'hspace': 0.04}
1536+
expected = tuple([*params.values()])
1537+
fig = plt.figure(layout=mpl.layout_engine.ConstrainedLayoutEngine(**params))
1538+
with pytest.warns(PendingDeprecationWarning, match="will be deprecated"):
1539+
assert fig.get_constrained_layout_pads() == expected

0 commit comments

Comments
 (0)