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

Skip to content

Commit 777b8ef

Browse files
committed
FIX: review comments
1 parent b6b8f10 commit 777b8ef

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def do_constrained_layout(fig, h_pad, w_pad,
8787
of 0.1 of the figure width between each column.
8888
If h/wspace < h/w_pad, then the pads are used instead.
8989
90+
compress : bool
91+
Whether to shift Axes so that white space in between them is
92+
removed. This is useful for simple grids of fixed-aspect Axes (e.g.
93+
a grid of images).
94+
9095
Returns
9196
-------
9297
layoutgrid : private debugging structure

lib/matplotlib/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,8 +2357,8 @@ def set_layout_engine(self, layout=None, **kwargs):
23572357
elif layout == 'constrained':
23582358
new_layout_engine = ConstrainedLayoutEngine(**kwargs)
23592359
elif layout == 'compressed':
2360-
kwargs['compress'] = True
2361-
new_layout_engine = ConstrainedLayoutEngine(**kwargs)
2360+
new_layout_engine = ConstrainedLayoutEngine(compress=True,
2361+
**kwargs)
23622362
elif isinstance(layout, LayoutEngine):
23632363
new_layout_engine = layout
23642364
else:

lib/matplotlib/layout_engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ def __init__(self, *, h_pad=None, w_pad=None,
197197
Default to :rc:`figure.constrained_layout.hspace` and
198198
:rc:`figure.constrained_layout.wspace`.
199199
compress : bool
200-
Whether to use compressed layout or not; useful for fixed-aspect
201-
simple grids of axes (e.g. a grid of images). See
202-
:ref:`compressed_layout`.
200+
Whether to shift Axes so that white space in between them is
201+
removed. This is useful for simple grids of fixed-aspect Axes (e.g.
202+
a grid of images). See :ref:`compressed_layout`.
203203
"""
204204
super().__init__(**kwargs)
205205
# set the defaults:

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,14 @@ def example_plot(ax, fontsize=12, hide_labels=False):
400400

401401
fig = plt.figure()
402402
gs0 = fig.add_gridspec(1, 2, figure=fig, width_ratios=[1., 2.])
403-
gsl = gs0[0].subgridspec(2, 1)
404-
gsr = gs0[1].subgridspec(2, 2)
403+
gs_left = gs0[0].subgridspec(2, 1)
404+
gs_right = gs0[1].subgridspec(2, 2)
405405

406-
for gs in gsl:
406+
for gs in gs_left:
407407
ax = fig.add_subplot(gs)
408408
example_plot(ax)
409409
axs = []
410-
for gs in gsr:
410+
for gs in gs_right:
411411
ax = fig.add_subplot(gs)
412412
pcm = ax.pcolormesh(arr, **pc_kwargs)
413413
ax.set_xlabel('x-label')
@@ -456,18 +456,16 @@ def example_plot(ax, fontsize=12, hide_labels=False):
456456
# Grids of fixed aspect-ratio Axes: "compressed" layout
457457
# =====================================================
458458
#
459-
#
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:
459+
# ``constrained_layout`` operates on the grid of "original" positions for
460+
# axes. However, when Axes have fixed aspect ratios, one side is usually made
461+
# shorter, and leaves large gaps in the shortened direction. In the following,
462+
# the Axes are square, but the figure quite wide so there is a horizontal gap:
465463

466464
fig, axs = plt.subplots(2, 2, figsize=(5, 3),
467465
sharex=True, sharey=True, layout='constrained')
468466
for ax in axs.flat:
469467
ax.imshow(arr)
470-
fig.suptitle('Constrained layout: fixed-aspect plots')
468+
fig.suptitle("fixed-aspect plots, layout='constrained'")
471469

472470
# One obvious way of fixing this is to make the figure size more square,
473471
# however, closing the gaps exactly requires trial and error. For simple grids
@@ -477,7 +475,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
477475
sharex=True, sharey=True, layout='compressed')
478476
for ax in axs.flat:
479477
ax.imshow(arr)
480-
fig.suptitle('Compressed layout: fixed-aspect plots')
478+
fig.suptitle("fixed-aspect plots, layout='compressed'")
481479

482480

483481
###############################################################################

0 commit comments

Comments
 (0)