Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cbd09f4

Browse filesBrowse files
committed
Make set_constrained_layout_pads arguments explicit.
1 parent 833658b commit cbd09f4
Copy full SHA for cbd09f4

File tree

Expand file treeCollapse file tree

2 files changed

+18
-13
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-13
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+16-13Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,40 +2406,43 @@ def set_constrained_layout(self, constrained):
24062406

24072407
self.stale = True
24082408

2409-
def set_constrained_layout_pads(self, **kwargs):
2409+
def set_constrained_layout_pads(self, *, w_pad=None, h_pad=None,
2410+
wspace=None, hspace=None):
24102411
"""
2411-
Set padding for ``constrained_layout``. Note the kwargs can be passed
2412-
as a dictionary ``fig.set_constrained_layout(**paddict)``.
2412+
Set padding for ``constrained_layout``.
2413+
2414+
Tip: The parameters can be passed from a dictionary by using
2415+
``fig.set_constrained_layout(**pad_dict)``.
24132416
24142417
See :doc:`/tutorials/intermediate/constrainedlayout_guide`.
24152418
24162419
Parameters
24172420
----------
2418-
w_pad : float
2421+
w_pad : float, default: :rc:`figure.constrained_layout.w_pad`
24192422
Width padding in inches. This is the pad around Axes
24202423
and is meant to make sure there is enough room for fonts to
24212424
look good. Defaults to 3 pts = 0.04167 inches
24222425
2423-
h_pad : float
2426+
h_pad : float, default: :rc:`figure.constrained_layout.h_pad`
24242427
Height padding in inches. Defaults to 3 pts.
24252428
2426-
wspace : float
2429+
wspace : float, default: :rc:`figure.constrained_layout.wspace`
24272430
Width padding between subplots, expressed as a fraction of the
24282431
subplot width. The total padding ends up being w_pad + wspace.
24292432
2430-
hspace : float
2433+
hspace : float, default: :rc:`figure.constrained_layout.hspace`
24312434
Height padding between subplots, expressed as a fraction of the
24322435
subplot width. The total padding ends up being h_pad + hspace.
24332436
24342437
"""
24352438

2436-
todo = ['w_pad', 'h_pad', 'wspace', 'hspace']
2437-
for td in todo:
2438-
if td in kwargs and kwargs[td] is not None:
2439-
self._constrained_layout_pads[td] = kwargs[td]
2439+
for name, size in zip(['w_pad', 'h_pad', 'wspace', 'hspace'],
2440+
[w_pad, h_pad, wspace, hspace]):
2441+
if size is not None:
2442+
self._constrained_layout_pads[name] = size
24402443
else:
2441-
self._constrained_layout_pads[td] = (
2442-
mpl.rcParams['figure.constrained_layout.' + td])
2444+
self._constrained_layout_pads[name] = (
2445+
mpl.rcParams[f'figure.constrained_layout.{name}'])
24432446

24442447
def get_constrained_layout_pads(self, relative=False):
24452448
"""

‎lib/matplotlib/tests/test_constrainedlayout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_constrainedlayout.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ def test_constrained_layout13():
252252
for ax in axs.flat:
253253
pcm = example_pcolor(ax, fontsize=12)
254254
fig.colorbar(pcm, ax=ax, shrink=0.6, aspect=20., pad=0.02)
255+
with pytest.raises(TypeError, match='unexpected keyword argument'):
256+
fig.set_constrained_layout_pads(wpad=1, hpad=2)
255257
fig.set_constrained_layout_pads(w_pad=24./72., h_pad=24./72.)
256258

257259

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.