@@ -1570,8 +1570,9 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
15701570 wspace, hspace : float, default: None
15711571 The amount of width/height reserved for space between subfigures,
15721572 expressed as a fraction of the average subfigure width/height.
1573- If not given, the values will be inferred from a figure or
1574- rcParams when necessary.
1573+ If not given, the values will be inferred from rcParams if using
1574+ constrained layout (see `~.ConstrainedLayoutEngine`), or zero if
1575+ not using a layout engine.
15751576
15761577 width_ratios : array-like of length *ncols*, optional
15771578 Defines the relative widths of the columns. Each column gets a
@@ -1586,13 +1587,24 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
15861587 gs = GridSpec (nrows = nrows , ncols = ncols , figure = self ,
15871588 wspace = wspace , hspace = hspace ,
15881589 width_ratios = width_ratios ,
1589- height_ratios = height_ratios )
1590+ height_ratios = height_ratios ,
1591+ left = 0 , right = 1 , bottom = 0 , top = 1 )
15901592
15911593 sfarr = np .empty ((nrows , ncols ), dtype = object )
15921594 for i in range (ncols ):
15931595 for j in range (nrows ):
15941596 sfarr [j , i ] = self .add_subfigure (gs [j , i ], ** kwargs )
15951597
1598+ if self .get_layout_engine () is None and (wspace is not None or
1599+ hspace is not None ):
1600+ # Gridspec wspace and hspace is ignored on subfigure instantiation,
1601+ # and no space is left. So need to account for it here if required.
1602+ bottoms , tops , lefts , rights = gs .get_grid_positions (self )
1603+ for sfrow , bottom , top in zip (sfarr , bottoms , tops ):
1604+ for sf , left , right in zip (sfrow , lefts , rights ):
1605+ bbox = Bbox .from_extents (left , bottom , right , top )
1606+ sf ._redo_transform_rel_fig (bbox = bbox )
1607+
15961608 if squeeze :
15971609 # Discarding unneeded dimensions that equal 1. If we only have one
15981610 # subfigure, just return it instead of a 1-element array.
0 commit comments