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

Skip to content

Commit 8175f87

Browse files
committed
Mods from review
1 parent 435bbfb commit 8175f87

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,27 @@ def compress_fixed_aspect(layoutgrids, fig):
263263
ax.apply_aspect()
264264
sub = ax.get_subplotspec()
265265
gs = sub.get_gridspec()
266-
if gs not in extraw.keys():
266+
if gs not in extraw:
267267
extraw[gs] = np.zeros(gs.ncols)
268268
extrah[gs] = np.zeros(gs.nrows)
269269
orig = ax.get_position(original=True)
270270
actual = ax.get_position(original=False)
271271
dw = orig.width - actual.width
272272
if dw > 0:
273-
for i in sub.colspan:
274-
extraw[gs][i] = max(extraw[gs][i], dw)
273+
extraw[gs][sub.colspan] = np.maximum(extraw[gs][sub.colspan],
274+
dw)
275275
dh = orig.height - actual.height
276276
if dh > 0:
277-
for i in sub.rowspan:
278-
extrah[gs][i] = max(extrah[gs][i], dh)
277+
extrah[gs][sub.rowspan] = np.maximum(extrah[gs][sub.rowspan],
278+
dh)
279279

280-
layoutgrids[fig].edit_margin_min('left', np.sum(extraw[gs]) / 2)
281-
layoutgrids[fig].edit_margin_min('right', np.sum(extraw[gs]) / 2)
280+
w = np.sum(extraw[gs]) / 2
281+
layoutgrids[fig].edit_margin_min('left', w)
282+
layoutgrids[fig].edit_margin_min('right', w)
282283

283-
layoutgrids[fig].edit_margin_min('top', np.sum(extrah[gs]) / 2)
284-
layoutgrids[fig].edit_margin_min('bottom', np.sum(extrah[gs]) / 2)
284+
h = np.sum(extrah[gs]) / 2
285+
layoutgrids[fig].edit_margin_min('top', h)
286+
layoutgrids[fig].edit_margin_min('bottom', h)
285287
return layoutgrids
286288

287289

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ def set_layout_engine(self, layout=None, **kwargs):
23362336
----------
23372337
layout: {'constrained', 'compressed', 'tight'} or `~.LayoutEngine`
23382338
'constrained' will use `~.ConstrainedLayoutEngine`,
2339-
'compressed', will also use ConstrainedLayoutEngine, but with a
2339+
'compressed' will also use ConstrainedLayoutEngine, but with a
23402340
correction that attempts to make a good layout for fixed-aspect
23412341
ratio Axes. 'tight' uses `~.TightLayoutEngine`. Users and
23422342
libraries can define their own layout engines as well.

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
325325
# =================
326326
#
327327
# constrained_layout is meant to be used
328-
# with :func:`~matplotlib.figure.Figure.subplots`
328+
# with :func:`~matplotlib.figure.Figure.subplots`,
329329
# :func:`~matplotlib.figure.Figure.subplot_mosaic`, or
330330
# :func:`~matplotlib.gridspec.GridSpec` with
331331
# :func:`~matplotlib.figure.Figure.add_subplot`.
@@ -457,11 +457,11 @@ def example_plot(ax, fontsize=12, hide_labels=False):
457457
# =====================================================
458458
#
459459
#
460-
# By default, ``constrained_layout`` acts on the total size of an axes, but
461-
# when Axes have fixed aspect ratios, one side is made shorter. For a grid
462-
# of such Axes, this leaves a large gap in the shortened direction. For
463-
# instance in the following the Axes are sqaure, but the figure quite wide
464-
# so there is a horizontal gap:
460+
# By default, ``constrained_layout`` acts on the original position of an axes.
461+
# However, when Axes have fixed aspect ratios, one side is made shorter. For
462+
# a grid of such Axes, this can leave a large gap in the shortened direction.
463+
# In the following the Axes are square, but the figure quite wide so there is
464+
# a horizontal gap:
465465

466466
fig, axs = plt.subplots(2, 2, figsize=(5, 3),
467467
sharex=True, sharey=True, layout='constrained')

0 commit comments

Comments
 (0)