@@ -1553,8 +1553,9 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
1553
1553
wspace, hspace : float, default: None
1554
1554
The amount of width/height reserved for space between subfigures,
1555
1555
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.
1558
1559
1559
1560
width_ratios : array-like of length *ncols*, optional
1560
1561
Defines the relative widths of the columns. Each column gets a
@@ -1569,13 +1570,24 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
1569
1570
gs = GridSpec (nrows = nrows , ncols = ncols , figure = self ,
1570
1571
wspace = wspace , hspace = hspace ,
1571
1572
width_ratios = width_ratios ,
1572
- height_ratios = height_ratios )
1573
+ height_ratios = height_ratios ,
1574
+ left = 0 , right = 1 , bottom = 0 , top = 1 )
1573
1575
1574
1576
sfarr = np .empty ((nrows , ncols ), dtype = object )
1575
1577
for i in range (ncols ):
1576
1578
for j in range (nrows ):
1577
1579
sfarr [j , i ] = self .add_subfigure (gs [j , i ], ** kwargs )
1578
1580
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
+
1579
1591
if squeeze :
1580
1592
# Discarding unneeded dimensions that equal 1. If we only have one
1581
1593
# subfigure, just return it instead of a 1-element array.
0 commit comments