@@ -254,7 +254,7 @@ def __init__(self,
254
254
linewidth = 0.0 , # the default linewidth of the frame
255
255
frameon = True , # whether or not to draw the figure frame
256
256
subplotpars = None , # default to rc
257
- tight = None , # whether to apply tight_layout
257
+ tight_layout = None , # default to rc figure.autolayout
258
258
):
259
259
"""
260
260
*figsize*
@@ -278,7 +278,7 @@ def __init__(self,
278
278
*subplotpars*
279
279
A :class:`SubplotParams` instance, defaults to rc
280
280
281
- *tight *
281
+ *tight_layout *
282
282
If *False* use *subplotpars*; if *True* adjust subplot
283
283
parameters using :meth:`tight_layout`. Defaults to
284
284
rc ``figure.autolayout``.
@@ -317,7 +317,7 @@ def __init__(self,
317
317
subplotpars = SubplotParams ()
318
318
319
319
self .subplotpars = subplotpars
320
- self ._set_tight ( tight )
320
+ self .set_tight_layout ( tight_layout )
321
321
322
322
self ._axstack = AxesStack () # track all figure axes and current axes
323
323
self .clf ()
@@ -336,15 +336,23 @@ def _set_dpi(self, dpi):
336
336
self .callbacks .process ('dpi_changed' , self )
337
337
dpi = property (_get_dpi , _set_dpi )
338
338
339
- def _get_tight (self ):
339
+ def get_tight_layout (self ):
340
+ """
341
+ Return the Boolean flag, True to use :meth`tight_layout` when drawing.
342
+ """
340
343
return self ._tight
341
- def _set_tight (self , tight ):
344
+
345
+ def set_tight_layout (self , tight ):
346
+ """
347
+ Set whether :meth:`tight_layout` is used upon drawing.
348
+ If None, the rcParams['figure.autolayout'] value will be set.
349
+
350
+ ACCEPTS: [True | False | None]
351
+ """
342
352
if tight is None :
343
353
tight = rcParams ['figure.autolayout' ]
344
354
tight = bool (tight )
345
355
self ._tight = tight
346
- tight = property (_get_tight , _set_tight ,
347
- doc = "If *True*, use :meth:`tight_layout`" )
348
356
349
357
def autofmt_xdate (self , bottom = 0.2 , rotation = 30 , ha = 'right' ):
350
358
"""
@@ -880,7 +888,7 @@ def draw(self, renderer):
880
888
if not self .get_visible (): return
881
889
renderer .open_group ('figure' )
882
890
883
- if self .tight and self .axes :
891
+ if self .get_tight_layout () and self .axes :
884
892
try :
885
893
self .tight_layout (renderer )
886
894
except ValueError :
@@ -1262,7 +1270,7 @@ def colorbar(self, mappable, cax=None, ax=None, **kw):
1262
1270
"""
1263
1271
if ax is None :
1264
1272
ax = self .gca ()
1265
- use_gridspec = kw .pop ("use_gridspec" , False )
1273
+ use_gridspec = kw .pop ("use_gridspec" , True )
1266
1274
if cax is None :
1267
1275
if use_gridspec and isinstance (ax , SubplotBase ):
1268
1276
cax , kw = cbar .make_axes_gridspec (ax , ** kw )
@@ -1405,6 +1413,12 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=Non
1405
1413
1406
1414
from tight_layout import get_renderer , get_tight_layout_figure
1407
1415
1416
+ no_go = [ax for ax in self .axes if not isinstance (ax , SubplotBase )]
1417
+ if no_go :
1418
+ warnings .Warn ("Cannot use tight_layout;"
1419
+ " all Axes must descend from SubplotBase" )
1420
+ return
1421
+
1408
1422
if renderer is None :
1409
1423
renderer = get_renderer (self )
1410
1424
0 commit comments