@@ -1553,8 +1553,9 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
15531553 wspace, hspace : float, default: None
15541554 The amount of width/height reserved for space between subfigures,
15551555 expressed as a fraction of the average subfigure width/height.
1556- If not given, the values will be inferred from a figure or
1557- rcParams when necessary.
1556+ If not given, the values will be inferred from rcParams if using
1557+ constrained layout (see `~.ConstrainedLayoutEngine`), or zero if
1558+ not using a layout engine.
15581559
15591560 width_ratios : array-like of length *ncols*, optional
15601561 Defines the relative widths of the columns. Each column gets a
@@ -1569,13 +1570,24 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
15691570 gs = GridSpec (nrows = nrows , ncols = ncols , figure = self ,
15701571 wspace = wspace , hspace = hspace ,
15711572 width_ratios = width_ratios ,
1572- height_ratios = height_ratios )
1573+ height_ratios = height_ratios ,
1574+ left = 0 , right = 1 , bottom = 0 , top = 1 )
15731575
15741576 sfarr = np .empty ((nrows , ncols ), dtype = object )
15751577 for i in range (ncols ):
15761578 for j in range (nrows ):
15771579 sfarr [j , i ] = self .add_subfigure (gs [j , i ], ** kwargs )
15781580
1581+ if self .get_layout_engine () is None and (wspace is not None or
1582+ hspace is not None ):
1583+ # Gridspec wspace and hspace is ignored on subfigure instantiation,
1584+ # and no space is left. So need to account for it here if required.
1585+ bottoms , tops , lefts , rights = gs .get_grid_positions (self )
1586+ for sfrow , bottom , top in zip (sfarr , bottoms , tops ):
1587+ for sf , left , right in zip (sfrow , lefts , rights ):
1588+ bbox = Bbox .from_extents (left , bottom , right , top )
1589+ sf ._redo_transform_rel_fig (bbox = bbox )
1590+
15791591 if squeeze :
15801592 # Discarding unneeded dimensions that equal 1. If we only have one
15811593 # subfigure, just return it instead of a 1-element array.
0 commit comments