@@ -1564,8 +1564,9 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
15641564 wspace, hspace : float, default: None
15651565 The amount of width/height reserved for space between subfigures,
15661566 expressed as a fraction of the average subfigure width/height.
1567- If not given, the values will be inferred from a figure or
1568- rcParams when necessary.
1567+ If not given, the values will be inferred from rcParams if using
1568+ constrained layout (see `~.ConstrainedLayoutEngine`), or zero if
1569+ not using a layout engine.
15691570
15701571 width_ratios : array-like of length *ncols*, optional
15711572 Defines the relative widths of the columns. Each column gets a
@@ -1580,13 +1581,24 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
15801581 gs = GridSpec (nrows = nrows , ncols = ncols , figure = self ,
15811582 wspace = wspace , hspace = hspace ,
15821583 width_ratios = width_ratios ,
1583- height_ratios = height_ratios )
1584+ height_ratios = height_ratios ,
1585+ left = 0 , right = 1 , bottom = 0 , top = 1 )
15841586
15851587 sfarr = np .empty ((nrows , ncols ), dtype = object )
15861588 for i in range (ncols ):
15871589 for j in range (nrows ):
15881590 sfarr [j , i ] = self .add_subfigure (gs [j , i ], ** kwargs )
15891591
1592+ if self .get_layout_engine () is None and (wspace is not None or
1593+ hspace is not None ):
1594+ # Gridspec wspace and hspace is ignored on subfigure instantiation,
1595+ # and no space is left. So need to account for it here if required.
1596+ bottoms , tops , lefts , rights = gs .get_grid_positions (self )
1597+ for sfrow , bottom , top in zip (sfarr , bottoms , tops ):
1598+ for sf , left , right in zip (sfrow , lefts , rights ):
1599+ bbox = Bbox .from_extents (left , bottom , right , top )
1600+ sf ._redo_transform_rel_fig (bbox = bbox )
1601+
15901602 if squeeze :
15911603 # Discarding unneeded dimensions that equal 1. If we only have one
15921604 # subfigure, just return it instead of a 1-element array.
0 commit comments