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

Skip to content

Commit 5380aa1

Browse files
committed
FIXes
1 parent e303fbb commit 5380aa1

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ def compress_fixed_aspect(layoutgrids, fig):
265265
gs = None
266266
for ax in fig.axes:
267267
if hasattr(ax, 'get_subplotspec'):
268-
actual = ax.get_position(original=False)
269268
ax.apply_aspect()
270269
sub = ax.get_subplotspec()
271270
_gs = sub.get_gridspec()
@@ -285,18 +284,17 @@ def compress_fixed_aspect(layoutgrids, fig):
285284
if dh > 0:
286285
extrah[sub.rowspan] = np.maximum(extrah[sub.rowspan], dh)
287286

288-
if gs is not None:
289-
w = np.sum(extraw) / 2
290-
layoutgrids[fig].edit_margin_min('left', w)
291-
layoutgrids[fig].edit_margin_min('right', w)
292-
293-
h = np.sum(extrah) / 2
294-
layoutgrids[fig].edit_margin_min('top', h)
295-
layoutgrids[fig].edit_margin_min('bottom', h)
296-
return layoutgrids
297-
else:
287+
if gs is None:
298288
raise ValueError('Cannot do compressed layout if no axes '
299289
'are part of a gridspec.')
290+
w = np.sum(extraw) / 2
291+
layoutgrids[fig].edit_margin_min('left', w)
292+
layoutgrids[fig].edit_margin_min('right', w)
293+
294+
h = np.sum(extrah) / 2
295+
layoutgrids[fig].edit_margin_min('top', h)
296+
layoutgrids[fig].edit_margin_min('bottom', h)
297+
return layoutgrids
300298

301299

302300
def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,

lib/matplotlib/layout_engine.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def __init__(self, *, h_pad=None, w_pad=None,
216216
# set anything that was passed in (None will be ignored):
217217
self.set(w_pad=w_pad, h_pad=h_pad, wspace=wspace, hspace=hspace,
218218
rect=rect)
219-
# see CompressedLayoutEngine below...
220219
self._compress = compress
221220

222221
def execute(self, fig):

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
399399
# the same effect can be achieved using `~.Figure.subfigures`.
400400

401401
fig = plt.figure()
402-
gs0 = fig.add_gridspec(1, 2, figure=fig, width_ratios=[1., 2.])
402+
gs0 = fig.add_gridspec(1, 2, figure=fig, width_ratios=[1, 2])
403403
gs_left = gs0[0].subgridspec(2, 1)
404404
gs_right = gs0[1].subgridspec(2, 2)
405405

@@ -424,17 +424,17 @@ def example_plot(ax, fontsize=12, hide_labels=False):
424424
fig = plt.figure()
425425
sfigs = fig.subfigures(1, 2, width_ratios=[1, 2])
426426

427-
axsleft = sfigs[0].subplots(2, 1)
428-
for ax in axsleft.flat:
427+
axs_left = sfigs[0].subplots(2, 1)
428+
for ax in axs_left.flat:
429429
example_plot(ax)
430430

431-
axsright = sfigs[1].subplots(2, 2)
432-
for ax in axsright.flat:
431+
axs_right = sfigs[1].subplots(2, 2)
432+
for ax in axs_right.flat:
433433
pcm = ax.pcolormesh(arr, **pc_kwargs)
434434
ax.set_xlabel('x-label')
435435
ax.set_ylabel('y-label')
436436
ax.set_title('title')
437-
fig.colorbar(pcm, ax=axsright)
437+
fig.colorbar(pcm, ax=axs_right)
438438
fig.suptitle('Nested plots using subfigures')
439439

440440
###############################################################################
@@ -467,7 +467,8 @@ def example_plot(ax, fontsize=12, hide_labels=False):
467467
ax.imshow(arr)
468468
fig.suptitle("fixed-aspect plots, layout='constrained'")
469469

470-
# One obvious way of fixing this is to make the figure size more square,
470+
###############################################################################
471+
# One obvious way of fixing this is to make the figure size more square,
471472
# however, closing the gaps exactly requires trial and error. For simple grids
472473
# of Axes we can use ``layout="compressed"`` to do the job for us:
473474

0 commit comments

Comments
 (0)