@@ -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
337338gs1 = gridspec .GridSpec (2 , 1 , figure = fig )
338339ax1 = 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
351352gs0 = 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
378379gs0 = 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" )
402403gs0 = fig .add_gridspec (1 , 2 , figure = fig , width_ratios = [1 , 2 ])
403404gs_left = gs0 [0 ].subgridspec (2 , 1 )
404405gs_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" )
425426sfigs = fig .subfigures (1 , 2 , width_ratios = [1 , 2 ])
426427
427428axs_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" )
450451example_plot (axs [0 ], fontsize = 12 )
451452axs [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
464465fig , axs = plt .subplots (2 , 2 , figsize = (5 , 3 ),
465- sharex = True , sharey = True , layout = ' constrained' )
466+ sharex = True , sharey = True , layout = " constrained" )
466467for ax in axs .flat :
467468 ax .imshow (arr )
468469fig .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
512513ax1 = plt .subplot (2 , 2 , 1 )
513514ax2 = 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
527528ax1 = plt .subplot (2 , 2 , 1 )
528529ax2 = 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
543544ax1 = plt .subplot2grid ((3 , 3 ), (0 , 0 ))
544545ax2 = plt .subplot2grid ((3 , 3 ), (0 , 1 ), colspan = 2 )
0 commit comments