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