@@ -332,7 +332,8 @@ def example_plot(ax, fontsize=12, hide_labels=False):
332
332
#
333
333
# Note that in what follows ``layout="constrained"``
334
334
335
- fig = plt .figure ()
335
+ plt .rcParams ['figure.constrained_layout.use' ] = False
336
+ fig = plt .figure (layout = "constrained" )
336
337
337
338
gs1 = gridspec .GridSpec (2 , 1 , figure = fig )
338
339
ax1 = fig .add_subplot (gs1 [0 ])
@@ -346,7 +347,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
346
347
# convenience functions `~.Figure.add_gridspec` and
347
348
# `~.SubplotSpec.subgridspec`.
348
349
349
- fig = plt .figure ()
350
+ fig = plt .figure (layout = "constrained" )
350
351
351
352
gs0 = fig .add_gridspec (1 , 2 )
352
353
@@ -373,7 +374,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
373
374
# then they need to be in the same gridspec. We need to make this figure
374
375
# larger as well in order for the axes not to collapse to zero height:
375
376
376
- fig = plt .figure (figsize = (4 , 6 ))
377
+ fig = plt .figure (figsize = (4 , 6 ), layout = "constrained" )
377
378
378
379
gs0 = fig .add_gridspec (6 , 2 )
379
380
@@ -398,7 +399,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
398
399
# subplots to be the same size you only needed one gridspec. Note that
399
400
# the same effect can be achieved using `~.Figure.subfigures`.
400
401
401
- fig = plt .figure ()
402
+ fig = plt .figure (layout = "constrained" )
402
403
gs0 = fig .add_gridspec (1 , 2 , figure = fig , width_ratios = [1 , 2 ])
403
404
gs_left = gs0 [0 ].subgridspec (2 , 1 )
404
405
gs_right = gs0 [1 ].subgridspec (2 , 2 )
@@ -421,7 +422,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
421
422
# Rather than using subgridspecs, Matplotlib now provides `~.Figure.subfigures`
422
423
# which also work with ``constrained_layout``:
423
424
424
- fig = plt .figure ()
425
+ fig = plt .figure (layout = "constrained" )
425
426
sfigs = fig .subfigures (1 , 2 , width_ratios = [1 , 2 ])
426
427
427
428
axs_left = sfigs [0 ].subplots (2 , 1 )
@@ -446,7 +447,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
446
447
# no effect on it anymore. (Note that ``constrained_layout`` still leaves the
447
448
# space for the axes that is moved).
448
449
449
- fig , axs = plt .subplots (1 , 2 )
450
+ fig , axs = plt .subplots (1 , 2 , layout = "constrained" )
450
451
example_plot (axs [0 ], fontsize = 12 )
451
452
axs [1 ].set_position ([0.2 , 0.2 , 0.4 , 0.4 ])
452
453
@@ -462,7 +463,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
462
463
# the Axes are square, but the figure quite wide so there is a horizontal gap:
463
464
464
465
fig , axs = plt .subplots (2 , 2 , figsize = (5 , 3 ),
465
- sharex = True , sharey = True , layout = ' constrained' )
466
+ sharex = True , sharey = True , layout = " constrained" )
466
467
for ax in axs .flat :
467
468
ax .imshow (arr )
468
469
fig .suptitle ("fixed-aspect plots, layout='constrained'" )
@@ -507,7 +508,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
507
508
# `.GridSpec` instance if the geometry is not the same, and
508
509
# ``constrained_layout``. So the following works fine:
509
510
510
- fig = plt .figure ()
511
+ fig = plt .figure (layout = "constrained" )
511
512
512
513
ax1 = plt .subplot (2 , 2 , 1 )
513
514
ax2 = plt .subplot (2 , 2 , 3 )
@@ -522,7 +523,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
522
523
###############################################################################
523
524
# but the following leads to a poor layout:
524
525
525
- fig = plt .figure ()
526
+ fig = plt .figure (layout = "constrained" )
526
527
527
528
ax1 = plt .subplot (2 , 2 , 1 )
528
529
ax2 = plt .subplot (2 , 2 , 3 )
@@ -538,7 +539,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
538
539
# `~matplotlib.pyplot.subplot2grid` works with the same limitation
539
540
# that nrows and ncols cannot change for the layout to look good.
540
541
541
- fig = plt .figure ()
542
+ fig = plt .figure (layout = "constrained" )
542
543
543
544
ax1 = plt .subplot2grid ((3 , 3 ), (0 , 0 ))
544
545
ax2 = plt .subplot2grid ((3 , 3 ), (0 , 1 ), colspan = 2 )
0 commit comments