diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index a708b0fd0bb..4cb39dfd484 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -43,9 +43,12 @@ def __init__(self, nrows, ncols, """ #self.figure = figure self._nrows , self._ncols = nrows, ncols - self.set_height_ratios(height_ratios) self.set_width_ratios(width_ratios) + # setting this to None because there is no reason to let + # the tight rectangle be set at instantiation. + self.set_tight_rect(None) + def get_geometry(self): 'get the geometry of the grid, e.g., 2,3' @@ -133,9 +136,19 @@ def get_grid_positions(self, fig): figLefts = [left + cellWs[2*colNum] for colNum in range(ncols)] figRights = [left + cellWs[2*colNum+1] for colNum in range(ncols)] - return figBottoms, figTops, figLefts, figRights + def get_tight_rect(self): + 'get the rectangle for use with gridspec.tight_layout' + return self._tight_rect + + def set_tight_rect(self, tight_rect): + 'set a rectangle for use with gridspec.tight_layout' + if tight_rect is not None and len(tight_rect) != 4: + raise ValueError('Expected keyword rect to be a list or tuple' + 'with four elements') + self._tight_rect = tight_rect + def __getitem__(self, key): """ create and return a SuplotSpec instance. @@ -307,6 +320,9 @@ def tight_layout(self, fig, renderer=None, pad=1.08, h_pad=None, w_pad=None, rec if renderer is None: renderer = get_renderer(fig) + if rect is None: + rect = self.get_tight_rect() + kwargs = get_tight_layout_figure(fig, fig.axes, subplotspec_list, renderer, pad=pad, h_pad=h_pad, w_pad=w_pad,