@@ -78,7 +78,7 @@ def example_plot(ax, fontsize=12, nodec=False):
7878 ax .set_yticklabels ('' )
7979
8080
81- fig , ax = plt .subplots ()
81+ fig , ax = plt .subplots (constrained_layout = False )
8282example_plot (ax , fontsize = 24 )
8383
8484###############################################################################
@@ -334,8 +334,10 @@ def example_plot(ax, fontsize=12, nodec=False):
334334# with :func:`~matplotlib.figure.Figure.subplots` or
335335# :func:`~matplotlib.gridspec.GridSpec` and
336336# :func:`~matplotlib.figure.Figure.add_subplot`.
337+ #
338+ # Note that in what follows ``constrained_layout=True``
337339
338- fig = plt .figure (constrained_layout = True )
340+ fig = plt .figure ()
339341
340342gs1 = gridspec .GridSpec (2 , 1 , figure = fig )
341343ax1 = fig .add_subplot (gs1 [0 ])
@@ -345,20 +347,21 @@ def example_plot(ax, fontsize=12, nodec=False):
345347example_plot (ax2 )
346348
347349###############################################################################
348- # More complicated gridspec layouts are possible.
350+ # More complicated gridspec layouts are possible. Note here we use the
351+ # convenenience functions ``add_gridspec`` and ``subgridspec``
349352
350- fig = plt .figure (constrained_layout = True )
353+ fig = plt .figure ()
351354
352- gs0 = gridspec . GridSpec (1 , 2 , figure = fig )
355+ gs0 = fig . add_gridspec (1 , 2 )
353356
354- gs1 = gridspec . GridSpecFromSubplotSpec (2 , 1 , gs0 [ 0 ] )
357+ gs1 = gs0 [ 0 ]. subgridspec (2 , 1 )
355358ax1 = fig .add_subplot (gs1 [0 ])
356359ax2 = fig .add_subplot (gs1 [1 ])
357360
358361example_plot (ax1 )
359362example_plot (ax2 )
360363
361- gs2 = gridspec . GridSpecFromSubplotSpec (3 , 1 , gs0 [ 1 ] )
364+ gs2 = gs0 [ 1 ]. subgridspec (3 , 1 )
362365
363366for ss in gs2 :
364367 ax = fig .add_subplot (ss )
@@ -373,9 +376,9 @@ def example_plot(ax, fontsize=12, nodec=False):
373376# extent. If we want the top and bottom of the two grids to line up then
374377# they need to be in the same gridspec:
375378
376- fig = plt .figure (constrained_layout = True )
379+ fig = plt .figure ()
377380
378- gs0 = gridspec . GridSpec (6 , 2 , figure = fig )
381+ gs0 = fig . add_gridspec (6 , 2 )
379382
380383ax1 = fig .add_subplot (gs0 [:3 , 0 ])
381384ax2 = fig .add_subplot (gs0 [3 :, 0 ])
@@ -398,10 +401,10 @@ def example_plot(ax, fontsize=12, nodec=False):
398401
399402
400403def docomplicated (suptitle = None ):
401- fig = plt .figure (constrained_layout = True )
402- gs0 = gridspec . GridSpec (1 , 2 , figure = fig , width_ratios = [1. , 2. ])
403- gsl = gridspec . GridSpecFromSubplotSpec (2 , 1 , gs0 [ 0 ] )
404- gsr = gridspec . GridSpecFromSubplotSpec (2 , 2 , gs0 [ 1 ] )
404+ fig = plt .figure ()
405+ gs0 = fig . add_gridspec (1 , 2 , figure = fig , width_ratios = [1. , 2. ])
406+ gsl = gs0 [ 0 ]. subgridspec (2 , 1 )
407+ gsr = gs0 [ 1 ]. subgridspec (2 , 2 )
405408
406409 for gs in gsl :
407410 ax = fig .add_subplot (gs )
@@ -430,7 +433,7 @@ def docomplicated(suptitle=None):
430433# no effect on it anymore. (Note that constrained_layout still leaves the
431434# space for the axes that is moved).
432435
433- fig , axs = plt .subplots (1 , 2 , constrained_layout = True )
436+ fig , axs = plt .subplots (1 , 2 )
434437example_plot (axs [0 ], fontsize = 12 )
435438axs [1 ].set_position ([0.2 , 0.2 , 0.4 , 0.4 ])
436439
@@ -444,7 +447,7 @@ def docomplicated(suptitle=None):
444447
445448from matplotlib .transforms import Bbox
446449
447- fig , axs = plt .subplots (1 , 2 , constrained_layout = True )
450+ fig , axs = plt .subplots (1 , 2 )
448451example_plot (axs [0 ], fontsize = 12 )
449452fig .execute_constrained_layout ()
450453# put into data-space:
@@ -468,7 +471,7 @@ def docomplicated(suptitle=None):
468471# to yield a nice layout:
469472
470473
471- fig = plt .figure (constrained_layout = True )
474+ fig = plt .figure ()
472475
473476ax1 = plt .subplot (221 )
474477ax2 = plt .subplot (223 )
@@ -481,8 +484,8 @@ def docomplicated(suptitle=None):
481484###############################################################################
482485# Of course that layout is possible using a gridspec:
483486
484- fig = plt .figure (constrained_layout = True )
485- gs = gridspec . GridSpec (2 , 2 , figure = fig )
487+ fig = plt .figure ()
488+ gs = fig . add_gridspec (2 , 2 )
486489
487490ax1 = fig .add_subplot (gs [0 , 0 ])
488491ax2 = fig .add_subplot (gs [1 , 0 ])
@@ -497,7 +500,7 @@ def docomplicated(suptitle=None):
497500# :func:`~matplotlib.pyplot.subplot2grid` doesn't work for the same reason:
498501# each call creates a different parent gridspec.
499502
500- fig = plt .figure (constrained_layout = True )
503+ fig = plt .figure ()
501504
502505ax1 = plt .subplot2grid ((3 , 3 ), (0 , 0 ))
503506ax2 = plt .subplot2grid ((3 , 3 ), (0 , 1 ), colspan = 2 )
@@ -513,8 +516,8 @@ def docomplicated(suptitle=None):
513516# The way to make this plot compatible with ``constrained_layout`` is again
514517# to use ``gridspec`` directly
515518
516- fig = plt .figure (constrained_layout = True )
517- gs = gridspec . GridSpec (3 , 3 , figure = fig )
519+ fig = plt .figure ()
520+ gs = fig . add_gridspec (3 , 3 )
518521
519522ax1 = fig .add_subplot (gs [0 , 0 ])
520523ax2 = fig .add_subplot (gs [0 , 1 :])
0 commit comments