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

Skip to content

Commit 421c99e

Browse files
committed
DOC: fix the guide handling of rcParams
1 parent dbcb46c commit 421c99e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ def example_plot(ax, fontsize=12, hide_labels=False):
332332
#
333333
# Note that in what follows ``layout="constrained"``
334334

335-
fig = plt.figure()
335+
plt.rcParams['figure.constrained_layout.use'] = False
336+
fig = plt.figure(layout="constrained")
336337

337338
gs1 = gridspec.GridSpec(2, 1, figure=fig)
338339
ax1 = fig.add_subplot(gs1[0])
@@ -346,7 +347,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
346347
# convenience functions `~.Figure.add_gridspec` and
347348
# `~.SubplotSpec.subgridspec`.
348349

349-
fig = plt.figure()
350+
fig = plt.figure(layout="constrained")
350351

351352
gs0 = fig.add_gridspec(1, 2)
352353

@@ -373,7 +374,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
373374
# then they need to be in the same gridspec. We need to make this figure
374375
# larger as well in order for the axes not to collapse to zero height:
375376

376-
fig = plt.figure(figsize=(4, 6))
377+
fig = plt.figure(figsize=(4, 6), layout="constrained")
377378

378379
gs0 = fig.add_gridspec(6, 2)
379380

@@ -398,7 +399,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
398399
# subplots to be the same size you only needed one gridspec. Note that
399400
# the same effect can be achieved using `~.Figure.subfigures`.
400401

401-
fig = plt.figure()
402+
fig = plt.figure(layout="constrained")
402403
gs0 = fig.add_gridspec(1, 2, figure=fig, width_ratios=[1, 2])
403404
gs_left = gs0[0].subgridspec(2, 1)
404405
gs_right = gs0[1].subgridspec(2, 2)
@@ -421,7 +422,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
421422
# Rather than using subgridspecs, Matplotlib now provides `~.Figure.subfigures`
422423
# which also work with ``constrained_layout``:
423424

424-
fig = plt.figure()
425+
fig = plt.figure(layout="constrained")
425426
sfigs = fig.subfigures(1, 2, width_ratios=[1, 2])
426427

427428
axs_left = sfigs[0].subplots(2, 1)
@@ -446,7 +447,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
446447
# no effect on it anymore. (Note that ``constrained_layout`` still leaves the
447448
# space for the axes that is moved).
448449

449-
fig, axs = plt.subplots(1, 2)
450+
fig, axs = plt.subplots(1, 2, layout="constrained")
450451
example_plot(axs[0], fontsize=12)
451452
axs[1].set_position([0.2, 0.2, 0.4, 0.4])
452453

@@ -462,7 +463,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
462463
# the Axes are square, but the figure quite wide so there is a horizontal gap:
463464

464465
fig, axs = plt.subplots(2, 2, figsize=(5, 3),
465-
sharex=True, sharey=True, layout='constrained')
466+
sharex=True, sharey=True, layout="constrained")
466467
for ax in axs.flat:
467468
ax.imshow(arr)
468469
fig.suptitle("fixed-aspect plots, layout='constrained'")
@@ -507,7 +508,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
507508
# `.GridSpec` instance if the geometry is not the same, and
508509
# ``constrained_layout``. So the following works fine:
509510

510-
fig = plt.figure()
511+
fig = plt.figure(layout="constrained")
511512

512513
ax1 = plt.subplot(2, 2, 1)
513514
ax2 = plt.subplot(2, 2, 3)
@@ -522,7 +523,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
522523
###############################################################################
523524
# but the following leads to a poor layout:
524525

525-
fig = plt.figure()
526+
fig = plt.figure(layout="constrained")
526527

527528
ax1 = plt.subplot(2, 2, 1)
528529
ax2 = plt.subplot(2, 2, 3)
@@ -538,7 +539,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
538539
# `~matplotlib.pyplot.subplot2grid` works with the same limitation
539540
# that nrows and ncols cannot change for the layout to look good.
540541

541-
fig = plt.figure()
542+
fig = plt.figure(layout="constrained")
542543

543544
ax1 = plt.subplot2grid((3, 3), (0, 0))
544545
ax2 = plt.subplot2grid((3, 3), (0, 1), colspan=2)

0 commit comments

Comments
 (0)