def adjust_bbox(fig, format, bbox_inches):
    '\n    Temporarily adjust the figure so that only the specified area\n    (bbox_inches) is saved.\n\n    It modifies fig.bbox, fig.bbox_inches,\n    fig.transFigure._boxout, and fig.patch.  While the figure size\n    changes, the scale of the original figure is conserved.  A\n    function which restores the original values are returned.\n    '
    origBbox = fig.bbox
    origBboxInches = fig.bbox_inches
    _boxout = fig.transFigure._boxout
    asp_list = []
    locator_list = []
    for ax in fig.axes:
        pos = ax.get_position(original=False).frozen()
        locator_list.append(ax.get_axes_locator())
        asp_list.append(ax.get_aspect())

        def _l(a, r, pos=pos):
            return pos
        ax.set_axes_locator(_l)
        ax.set_aspect('auto')

    def restore_bbox():
        for (ax, asp, loc) in zip(fig.axes, asp_list, locator_list):
            ax.set_aspect(asp)
            ax.set_axes_locator(loc)
        fig.bbox = origBbox
        fig.bbox_inches = origBboxInches
        fig.transFigure._boxout = _boxout
        fig.transFigure.invalidate()
        fig.patch.set_bounds(0, 0, 1, 1)
    adjust_bbox_handler = _adjust_bbox_handler_d.get(format)
    if (adjust_bbox_handler is not None):
        adjust_bbox_handler(fig, bbox_inches)
        return restore_bbox
    else:
        warnings.warn(('bbox_inches option for %s backend is not implemented yet.' % format))
        return None
Temporarily adjust the figure so that only the specified area
(bbox_inches) is saved.

It modifies fig.bbox, fig.bbox_inches,
fig.transFigure._boxout, and fig.patch.  While the figure size
changes, the scale of the original figure is conserved.  A
function which restores the original values are returned.
def adjust_bbox(fig, format, bbox_inches):
    '\n    Temporarily adjust the figure so that only the specified area\n    (bbox_inches) is saved.\n\n    It modifies fig.bbox, fig.bbox_inches,\n    fig.transFigure._boxout, and fig.patch.  While the figure size\n    changes, the scale of the original figure is conserved.  A\n    function which restores the original values are returned.\n    '
    origBbox = fig.bbox
    origBboxInches = fig.bbox_inches
    _boxout = fig.transFigure._boxout
    asp_list = []
    locator_list = []
    for ax in fig.axes:
        pos = ax.get_position(original=False).frozen()
        locator_list.append(ax.get_axes_locator())
        asp_list.append(ax.get_aspect())

        def _l(a, r, pos=pos):
            return pos
        ax.set_axes_locator(_l)
        ax.set_aspect('auto')

    def restore_bbox():
        for (ax, asp, loc) in zip(fig.axes, asp_list, locator_list):
            ax.set_aspect(asp)
            ax.set_axes_locator(loc)
        fig.bbox = origBbox
        fig.bbox_inches = origBboxInches
        fig.transFigure._boxout = _boxout
        fig.transFigure.invalidate()
        fig.patch.set_bounds(0, 0, 1, 1)
    adjust_bbox_handler = _adjust_bbox_handler_d.get(format)
    if (adjust_bbox_handler is not None):
        adjust_bbox_handler(fig, bbox_inches)
        return restore_bbox
    else:
        warnings.warn(('bbox_inches option for %s backend is not implemented yet.' % format))
        return None