@@ -1564,8 +1564,10 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
1564
1564
wspace, hspace : float, default: None
1565
1565
The amount of width/height reserved for space between subfigures,
1566
1566
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
1569
+ :class:`~matplotlib.layout_engine.ConstrainedLayoutEngine`), or
1570
+ zero if not using a layout engine.
1569
1571
1570
1572
width_ratios : array-like of length *ncols*, optional
1571
1573
Defines the relative widths of the columns. Each column gets a
@@ -1580,13 +1582,24 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
1580
1582
gs = GridSpec (nrows = nrows , ncols = ncols , figure = self ,
1581
1583
wspace = wspace , hspace = hspace ,
1582
1584
width_ratios = width_ratios ,
1583
- height_ratios = height_ratios )
1585
+ height_ratios = height_ratios ,
1586
+ left = 0 , right = 1 , bottom = 0 , top = 1 )
1584
1587
1585
1588
sfarr = np .empty ((nrows , ncols ), dtype = object )
1586
1589
for i in range (ncols ):
1587
1590
for j in range (nrows ):
1588
1591
sfarr [j , i ] = self .add_subfigure (gs [j , i ], ** kwargs )
1589
1592
1593
+ if self .get_layout_engine () is None and (wspace is not None or
1594
+ hspace is not None ):
1595
+ # Gridspec wspace and hspace is ignored on subfigure instantiation,
1596
+ # and no space is left. So need to account for it here if required.
1597
+ bottoms , tops , lefts , rights = gs .get_grid_positions (self )
1598
+ for sfrow , bottom , top in zip (sfarr , bottoms , tops ):
1599
+ for sf , left , right in zip (sfrow , lefts , rights ):
1600
+ bbox = Bbox .from_extents (left , bottom , right , top )
1601
+ sf ._redo_transform_rel_fig (bbox = bbox )
1602
+
1590
1603
if squeeze :
1591
1604
# Discarding unneeded dimensions that equal 1. If we only have one
1592
1605
# subfigure, just return it instead of a 1-element array.
0 commit comments