@@ -38,7 +38,8 @@ def auto_adjust_subplotpars(
38
38
fig , renderer , nrows_ncols , num1num2_list , subplot_list ,
39
39
ax_bbox_list = None , pad = 1.08 , h_pad = None , w_pad = None , rect = None ):
40
40
"""
41
- Return a dict of subplot parameters to adjust spacing between subplots.
41
+ Return a dict of subplot parameters to adjust spacing between subplots
42
+ or ``None`` if resulting axes would have zero height or width.
42
43
43
44
Note that this function ignores geometry information of subplot
44
45
itself, but uses what is given by the *nrows_ncols* and *num1num2_list*
@@ -172,15 +173,15 @@ def auto_adjust_subplotpars(
172
173
margin_bottom += pad_inches / fig_height_inch
173
174
174
175
if margin_left + margin_right >= 1 :
175
- margin_left = 0.4999
176
- margin_right = 0.4999
177
- warnings .warn ('The left and right margins cannot be made large '
176
+ warnings .warn ('Tight layout not applied. The left and right margins '
177
+ 'cannot be made large '
178
178
'enough to accommodate all axes decorations. ' )
179
+ return None
179
180
if margin_bottom + margin_top >= 1 :
180
- margin_bottom = 0.4999
181
- margin_top = 0.4999
182
- warnings .warn ('The bottom and top margins cannot be made large '
181
+ warnings .warn ('Tight layout not applied. '
182
+ 'The bottom and top margins cannot be made large '
183
183
'enough to accommodate all axes decorations. ' )
184
+ return None
184
185
185
186
kwargs = dict (left = margin_left ,
186
187
right = 1 - margin_right ,
@@ -195,9 +196,10 @@ def auto_adjust_subplotpars(
195
196
# axes widths:
196
197
h_axes = (1 - margin_right - margin_left - hspace * (cols - 1 )) / cols
197
198
if h_axes < 0 :
198
- warnings .warn ('tight_layout cannot make axes width small enough '
199
+ warnings .warn ('Tight layout not applied. '
200
+ 'tight_layout cannot make axes width small enough '
199
201
'to accommodate all axes decorations' )
200
- kwargs [ "wspace" ] = 0.5
202
+ return None
201
203
else :
202
204
kwargs ["wspace" ] = hspace / h_axes
203
205
@@ -206,9 +208,10 @@ def auto_adjust_subplotpars(
206
208
+ vpad_inches / fig_height_inch )
207
209
v_axes = (1 - margin_top - margin_bottom - vspace * (rows - 1 )) / rows
208
210
if v_axes < 0 :
209
- warnings .warn ('tight_layout cannot make axes height small enough '
211
+ warnings .warn ('Tight layout not applied. '
212
+ 'tight_layout cannot make axes height small enough '
210
213
'to accommodate all axes decorations' )
211
- kwargs [ "hspace" ] = 0.5
214
+ return None
212
215
else :
213
216
kwargs ["hspace" ] = vspace / v_axes
214
217
@@ -287,6 +290,13 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
287
290
(left, bottom, right, top) rectangle in normalized figure coordinates
288
291
that the whole subplots area (including labels) will fit into.
289
292
Defaults to using the entire figure.
293
+
294
+ Returns
295
+ -------
296
+ subplotspec or None
297
+ subplotspec kwargs to be passed to `.Figure.subplots_adjust` or
298
+ None if tight_layout could not be accomplished.
299
+
290
300
"""
291
301
292
302
subplot_list = []
0 commit comments