64
64
65
65
######################################################
66
66
def do_constrained_layout (fig , h_pad , w_pad ,
67
- hspace = None , wspace = None ):
67
+ hspace = None , wspace = None , rect = ( 0 , 0 , 1 , 1 ) ):
68
68
"""
69
69
Do the constrained_layout. Called at draw time in
70
70
``figure.constrained_layout()``
@@ -87,14 +87,18 @@ def do_constrained_layout(fig, h_pad, w_pad,
87
87
of 0.1 of the figure width between each column.
88
88
If h/wspace < h/w_pad, then the pads are used instead.
89
89
90
+ rect : tuple of 4 floats
91
+ Rectangle in figure coordinates to perform constrained layout in
92
+ [left, bottom, width, height], each from 0-1.
93
+
90
94
Returns
91
95
-------
92
96
layoutgrid : private debugging structure
93
97
"""
94
98
95
99
renderer = _get_renderer (fig )
96
100
# make layoutgrid tree...
97
- layoutgrids = make_layoutgrids (fig , None )
101
+ layoutgrids = make_layoutgrids (fig , None , rect = rect )
98
102
if not layoutgrids ['hasgrids' ]:
99
103
_api .warn_external ('There are no gridspecs with layoutgrids. '
100
104
'Possibly did not call parent GridSpec with the'
@@ -133,7 +137,7 @@ def do_constrained_layout(fig, h_pad, w_pad,
133
137
return layoutgrids
134
138
135
139
136
- def make_layoutgrids (fig , layoutgrids ):
140
+ def make_layoutgrids (fig , layoutgrids , rect = [ 0 , 0 , 1 , 1 ] ):
137
141
"""
138
142
Make the layoutgrid tree.
139
143
@@ -147,8 +151,9 @@ def make_layoutgrids(fig, layoutgrids):
147
151
layoutgrids = dict ()
148
152
layoutgrids ['hasgrids' ] = False
149
153
if not hasattr (fig , '_parent' ):
150
- # top figure
151
- layoutgrids [fig ] = mlayoutgrid .LayoutGrid (parent = None , name = 'figlb' )
154
+ # top figure; pass rect as parent to allow user-specified
155
+ # margins
156
+ layoutgrids [fig ] = mlayoutgrid .LayoutGrid (parent = rect , name = 'figlb' )
152
157
else :
153
158
# subfigure
154
159
gs = fig ._subplotspec .get_gridspec ()
0 commit comments