6464plt .rcParams ['savefig.facecolor' ] = "0.8"
6565plt .rcParams ['figure.figsize' ] = 4.5 , 4.
6666
67-
6867def example_plot (ax , fontsize = 12 , nodec = False ):
6968 ax .plot ([1 , 2 ])
7069
@@ -78,7 +77,7 @@ def example_plot(ax, fontsize=12, nodec=False):
7877 ax .set_yticklabels ('' )
7978
8079
81- fig , ax = plt .subplots ()
80+ fig , ax = plt .subplots (constrained_layout = False )
8281example_plot (ax , fontsize = 24 )
8382
8483###############################################################################
@@ -334,8 +333,10 @@ def example_plot(ax, fontsize=12, nodec=False):
334333# with :func:`~matplotlib.figure.Figure.subplots` or
335334# :func:`~matplotlib.gridspec.GridSpec` and
336335# :func:`~matplotlib.figure.Figure.add_subplot`.
336+ #
337+ # Note that in what follows ``constrained_layout=True``
337338
338- fig = plt .figure (constrained_layout = True )
339+ fig = plt .figure ()
339340
340341gs1 = gridspec .GridSpec (2 , 1 , figure = fig )
341342ax1 = fig .add_subplot (gs1 [0 ])
@@ -345,20 +346,21 @@ def example_plot(ax, fontsize=12, nodec=False):
345346example_plot (ax2 )
346347
347348###############################################################################
348- # More complicated gridspec layouts are possible.
349+ # More complicated gridspec layouts are possible. Note here we use the
350+ # convenenience functions ``add_gridspec`` and ``subgridspec``
349351
350- fig = plt .figure (constrained_layout = True )
352+ fig = plt .figure ()
351353
352- gs0 = gridspec . GridSpec (1 , 2 , figure = fig )
354+ gs0 = fig . add_gridspec (1 , 2 )
353355
354- gs1 = gridspec . GridSpecFromSubplotSpec (2 , 1 , gs0 [ 0 ] )
356+ gs1 = gs0 [ 0 ]. subgridspec (2 , 1 )
355357ax1 = fig .add_subplot (gs1 [0 ])
356358ax2 = fig .add_subplot (gs1 [1 ])
357359
358360example_plot (ax1 )
359361example_plot (ax2 )
360362
361- gs2 = gridspec . GridSpecFromSubplotSpec (3 , 1 , gs0 [ 1 ] )
363+ gs2 = gs0 [ 1 ]. subgridspec (3 , 1 )
362364
363365for ss in gs2 :
364366 ax = fig .add_subplot (ss )
@@ -373,9 +375,9 @@ def example_plot(ax, fontsize=12, nodec=False):
373375# extent. If we want the top and bottom of the two grids to line up then
374376# they need to be in the same gridspec:
375377
376- fig = plt .figure (constrained_layout = True )
378+ fig = plt .figure ()
377379
378- gs0 = gridspec . GridSpec (6 , 2 , figure = fig )
380+ gs0 = fig . add_gridspec (6 , 2 )
379381
380382ax1 = fig .add_subplot (gs0 [:3 , 0 ])
381383ax2 = fig .add_subplot (gs0 [3 :, 0 ])
@@ -398,10 +400,10 @@ def example_plot(ax, fontsize=12, nodec=False):
398400
399401
400402def 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 ] )
403+ fig = plt .figure ()
404+ gs0 = fig . add_gridspec (1 , 2 , figure = fig , width_ratios = [1. , 2. ])
405+ gsl = gs0 [ 0 ]. subgridspec (2 , 1 )
406+ gsr = gs0 [ 1 ]. subgridspec (2 , 2 )
405407
406408 for gs in gsl :
407409 ax = fig .add_subplot (gs )
@@ -430,7 +432,7 @@ def docomplicated(suptitle=None):
430432# no effect on it anymore. (Note that constrained_layout still leaves the
431433# space for the axes that is moved).
432434
433- fig , axs = plt .subplots (1 , 2 , constrained_layout = True )
435+ fig , axs = plt .subplots (1 , 2 )
434436example_plot (axs [0 ], fontsize = 12 )
435437axs [1 ].set_position ([0.2 , 0.2 , 0.4 , 0.4 ])
436438
@@ -444,7 +446,7 @@ def docomplicated(suptitle=None):
444446
445447from matplotlib .transforms import Bbox
446448
447- fig , axs = plt .subplots (1 , 2 , constrained_layout = True )
449+ fig , axs = plt .subplots (1 , 2 )
448450example_plot (axs [0 ], fontsize = 12 )
449451fig .execute_constrained_layout ()
450452# put into data-space:
@@ -468,7 +470,7 @@ def docomplicated(suptitle=None):
468470# to yield a nice layout:
469471
470472
471- fig = plt .figure (constrained_layout = True )
473+ fig = plt .figure ()
472474
473475ax1 = plt .subplot (221 )
474476ax2 = plt .subplot (223 )
@@ -481,8 +483,8 @@ def docomplicated(suptitle=None):
481483###############################################################################
482484# Of course that layout is possible using a gridspec:
483485
484- fig = plt .figure (constrained_layout = True )
485- gs = gridspec . GridSpec (2 , 2 , figure = fig )
486+ fig = plt .figure ()
487+ gs = fig . add_gridspec (2 , 2 )
486488
487489ax1 = fig .add_subplot (gs [0 , 0 ])
488490ax2 = fig .add_subplot (gs [1 , 0 ])
@@ -497,7 +499,7 @@ def docomplicated(suptitle=None):
497499# :func:`~matplotlib.pyplot.subplot2grid` doesn't work for the same reason:
498500# each call creates a different parent gridspec.
499501
500- fig = plt .figure (constrained_layout = True )
502+ fig = plt .figure ()
501503
502504ax1 = plt .subplot2grid ((3 , 3 ), (0 , 0 ))
503505ax2 = plt .subplot2grid ((3 , 3 ), (0 , 1 ), colspan = 2 )
@@ -513,8 +515,8 @@ def docomplicated(suptitle=None):
513515# The way to make this plot compatible with ``constrained_layout`` is again
514516# to use ``gridspec`` directly
515517
516- fig = plt .figure (constrained_layout = True )
517- gs = gridspec . GridSpec (3 , 3 , figure = fig )
518+ fig = plt .figure ()
519+ gs = fig . add_gridspec (3 , 3 )
518520
519521ax1 = fig .add_subplot (gs [0 , 0 ])
520522ax2 = fig .add_subplot (gs [0 , 1 :])
0 commit comments