lib/matplotlib/backend_bases.py
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
                     orientation='portrait', format=None, **kwargs):
        """
        Render the figure to hardcopy. Set the figure patch face and edge
        colors.  This is useful because some of the GUIs have a gray figure
        face color background and you'll probably want to override this on
        hardcopy.

        Arguments are:

        *filename*
            can also be a file object on image backends

        *orientation*
            only currently applies to PostScript printing.

        *dpi*
            the dots per inch to save the figure in; if None, use savefig.dpi

        *facecolor*
            the facecolor of the figure

        *edgecolor*
            the edgecolor of the figure

        *orientation*
            landscape' | 'portrait' (not supported on all backends)

        *format*
            when set, forcibly set the file format to save to


        *bbox_inches*
            Bbox in inches. Only the given portion of the figure is
            saved. If 'tight', try to figure out the tight bbox of
            the figure.

        *pad_inches*
            Amount of padding around the figure when bbox_inches is
            'tight'.

        *bbox_extra_artists*
            A list of extra artists that will be considered when the
            tight bbox is calculated.

        """
        if format is None:
            if cbook.is_string_like(filename):
                format = os.path.splitext(filename)[1][1:]
            if format is None or format == '':
                format = self.get_default_filetype()
                if cbook.is_string_like(filename):
                    filename = filename.rstrip('.') + '.' + format
        format = format.lower()

        method_name = 'print_%s' % format
        if (format not in self.filetypes or
            not hasattr(self, method_name)):
            formats = self.filetypes.keys()
            formats.sort()
            raise ValueError(
                'Format "%s" is not supported.\n'
                'Supported formats: '
                '%s.' % (format, ', '.join(formats)))

        if dpi is None:
            dpi = rcParams['savefig.dpi']

        origDPI = self.figure.dpi
        origfacecolor = self.figure.get_facecolor()
        origedgecolor = self.figure.get_edgecolor()

        self.figure.dpi = dpi
        self.figure.set_facecolor(facecolor)
        self.figure.set_edgecolor(edgecolor)

        bbox_inches = kwargs.pop("bbox_inches", None)

        if bbox_inches:
            # call adjust_bbox to save only the given area
            if bbox_inches == "tight":
                # when bbox_inches == "tight", it saves the figure
                # twice. The first save command is just to estimate
                # the bounding box of the figure. A stringIO object is
                # used as a temporary file object, but it causes a
                # problem for some backends (ps backend with
                # usetex=True) if they expect a filename, not a
                # file-like object. As I think it is best to change
                # the backend to support file-like object, i'm going
                # to leave it as it is. However, a better solution
                # than stringIO seems to be needed. -JJL
                result = getattr(self, method_name)(
                    cStringIO.StringIO(),
                    dpi=dpi,
                    facecolor=facecolor,
                    edgecolor=edgecolor,
                    orientation=orientation,
                    dryrun=True,
                    **kwargs)
                renderer = self.figure._cachedRenderer
                bbox_inches = self.figure.get_tightbbox(renderer)

                bb = [a.get_window_extent(renderer) for a \
                      in kwargs.pop("bbox_extra_artists", [])]
                if bb:
                    _bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])

                    bbox_inches1 = TransformedBbox(_bbox,
                                                  Affine2D().scale(1./self.figure.dpi))

                    bbox_inches = Bbox.union([bbox_inches, bbox_inches1])


                pad = kwargs.pop("pad_inches", 0.1)
                bbox_inches = bbox_inches.padded(pad)

            restore_bbox = tight_bbox.adjust_bbox(self.figure, format,
                                                  bbox_inches)

            _bbox_inches_restore = (bbox_inches, restore_bbox)
        else:
            _bbox_inches_restore = None

        try:
            result = getattr(self, method_name)(
                filename,
                dpi=dpi,
                facecolor=facecolor,
                edgecolor=edgecolor,
                orientation=orientation,
                bbox_inches_restore=_bbox_inches_restore,
                **kwargs)
        finally:
            if bbox_inches and restore_bbox:
                restore_bbox()

            self.figure.dpi = origDPI
            self.figure.set_facecolor(origfacecolor)
            self.figure.set_edgecolor(origedgecolor)
            self.figure.set_canvas(self)
            #self.figure.canvas.draw() ## seems superfluous
        return result

        Render the figure to hardcopy. Set the figure patch face and edge
        colors.  This is useful because some of the GUIs have a gray figure
        face color background and you'll probably want to override this on
        hardcopy.

        Arguments are:

        *filename*
            can also be a file object on image backends

        *orientation*
            only currently applies to PostScript printing.

        *dpi*
            the dots per inch to save the figure in; if None, use savefig.dpi

        *facecolor*
            the facecolor of the figure

        *edgecolor*
            the edgecolor of the figure

        *orientation*
            landscape' | 'portrait' (not supported on all backends)

        *format*
            when set, forcibly set the file format to save to


        *bbox_inches*
            Bbox in inches. Only the given portion of the figure is
            saved. If 'tight', try to figure out the tight bbox of
            the figure.

        *pad_inches*
            Amount of padding around the figure when bbox_inches is
            'tight'.

        *bbox_extra_artists*
            A list of extra artists that will be considered when the
            tight bbox is calculated.

        
Render the figure to hardcopy. Set the figure patch face and edge
colors.  This is useful because some of the GUIs have a gray figure
face color background and you'll probably want to override this on
hardcopy.

Arguments are.

filename
can also be a file object on image backends

orientation
only currently applies to PostScript printing.

dpi
the dots per inch to save the figure in; if None, use savefig.dpi

facecolor
the facecolor of the figure

edgecolor
the edgecolor of the figure

orientation
landscape' | 'portrait' (not supported on all backends)

format
when set, forcibly set the file format to save to

bbox_inches
Bbox in inches. Only the given portion of the figure is
saved. If 'tight', try to figure out the tight bbox of
the figure.

pad_inches
Amount of padding around the figure when bbox_inches is
'tight'.

bbox_extra_artists
A list of extra artists that will be considered when the
tight bbox is calculated.
Render the figure to hardcopy . Set the figure patch face and edge colors . This is useful because some of the GUIs have a gray figure face color background and you ' ll probably want to override this on hardcopy . Arguments are . filename can also be a file object on image backends orientation only currently applies to PostScript printing . dpi the dots per inch to save the figure in ; if None use savefig . dpi facecolor the facecolor of the figure edgecolor the edgecolor of the figure orientation landscape ' | ' portrait ' ( not supported on all backends ) format when set forcibly set the file format to save to bbox_inches Bbox in inches . Only the given portion of the figure is saved . If ' tight ' try to figure out the tight bbox of the figure . pad_inches Amount of padding around the figure when bbox_inches is ' tight ' . bbox_extra_artists A list of extra artists that will be considered when the tight bbox is calculated .
def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
                     orientation='portrait', format=None, **kwargs):
        if format is None:
            if cbook.is_string_like(filename):
                format = os.path.splitext(filename)[1][1:]
            if format is None or format == '':
                format = self.get_default_filetype()
                if cbook.is_string_like(filename):
                    filename = filename.rstrip('.') + '.' + format
        format = format.lower()
        method_name = 'print_%s' % format
        if (format not in self.filetypes or
            not hasattr(self, method_name)):
            formats = self.filetypes.keys()
            formats.sort()
            raise ValueError(
                'Format "%s" is not supported.\n'
                'Supported formats: '
                '%s.' % (format, ', '.join(formats)))
        if dpi is None:
            dpi = rcParams['savefig.dpi']
        origDPI = self.figure.dpi
        origfacecolor = self.figure.get_facecolor()
        origedgecolor = self.figure.get_edgecolor()
        self.figure.dpi = dpi
        self.figure.set_facecolor(facecolor)
        self.figure.set_edgecolor(edgecolor)
        bbox_inches = kwargs.pop("bbox_inches", None)
        if bbox_inches:
            if bbox_inches == "tight":
                result = getattr(self, method_name)(
                    cStringIO.StringIO(),
                    dpi=dpi,
                    facecolor=facecolor,
                    edgecolor=edgecolor,
                    orientation=orientation,
                    dryrun=True,
                    **kwargs)
                renderer = self.figure._cachedRenderer
                bbox_inches = self.figure.get_tightbbox(renderer)
                bb = [a.get_window_extent(renderer) for a \
                      in kwargs.pop("bbox_extra_artists", [])]
                if bb:
                    _bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])
                    bbox_inches1 = TransformedBbox(_bbox,
                                                  Affine2D().scale(1./self.figure.dpi))
                    bbox_inches = Bbox.union([bbox_inches, bbox_inches1])
                pad = kwargs.pop("pad_inches", 0.1)
                bbox_inches = bbox_inches.padded(pad)
            restore_bbox = tight_bbox.adjust_bbox(self.figure, format,
                                                  bbox_inches)
            _bbox_inches_restore = (bbox_inches, restore_bbox)
        else:
            _bbox_inches_restore = None
        try:
            result = getattr(self, method_name)(
                filename,
                dpi=dpi,
                facecolor=facecolor,
                edgecolor=edgecolor,
                orientation=orientation,
                bbox_inches_restore=_bbox_inches_restore,
                **kwargs)
        finally:
            if bbox_inches and restore_bbox:
                restore_bbox()
            self.figure.dpi = origDPI
            self.figure.set_facecolor(origfacecolor)
            self.figure.set_edgecolor(origedgecolor)
            self.figure.set_canvas(self)
        return result
def print_figure ( self , filename , dpi = None , facecolor = 'w' , edgecolor = 'w' , orientation = 'portrait' , format = None , ** kwargs ) : if format is None : if cbook . is_string_like ( filename ) : format = os . path . splitext ( filename ) [ 1 ] [ 1 : ] if format is None or format == '' : format = self . get_default_filetype ( ) if cbook . is_string_like ( filename ) : filename = filename . rstrip ( '.' ) + '.' + format format = format . lower ( ) method_name = 'print_%s' % format if ( format not in self . filetypes or not hasattr ( self , method_name ) ) : formats = self . filetypes . keys ( ) formats . sort ( ) raise ValueError ( 'Format "%s" is not supported.\n' 'Supported formats: ' '%s.' % ( format , ', ' . join ( formats ) ) ) if dpi is None : dpi = rcParams [ 'savefig.dpi' ] origDPI = self . figure . dpi origfacecolor = self . figure . get_facecolor ( ) origedgecolor = self . figure . get_edgecolor ( ) self . figure . dpi = dpi self . figure . set_facecolor ( facecolor ) self . figure . set_edgecolor ( edgecolor ) bbox_inches = kwargs . pop ( "bbox_inches" , None ) if bbox_inches : if bbox_inches == "tight" : result = getattr ( self , method_name ) ( cStringIO . StringIO ( ) , dpi = dpi , facecolor = facecolor , edgecolor = edgecolor , orientation = orientation , dryrun = True , ** kwargs ) renderer = self . figure . _cachedRenderer bbox_inches = self . figure . get_tightbbox ( renderer ) bb = [ a . get_window_extent ( renderer ) for a in kwargs . pop ( "bbox_extra_artists" , [ ] ) ] if bb : _bbox = Bbox . union ( [ b for b in bb if b . width != 0 or b . height != 0 ] ) bbox_inches1 = TransformedBbox ( _bbox , Affine2D ( ) . scale ( 1. / self . figure . dpi ) ) bbox_inches = Bbox . union ( [ bbox_inches , bbox_inches1 ] ) pad = kwargs . pop ( "pad_inches" , 0.1 ) bbox_inches = bbox_inches . padded ( pad ) restore_bbox = tight_bbox . adjust_bbox ( self . figure , format , bbox_inches ) _bbox_inches_restore = ( bbox_inches , restore_bbox ) else : _bbox_inches_restore = None try : result = getattr ( self , method_name ) ( filename , dpi = dpi , facecolor = facecolor , edgecolor = edgecolor , orientation = orientation , bbox_inches_restore = _bbox_inches_restore , ** kwargs ) finally : if bbox_inches and restore_bbox : restore_bbox ( ) self . figure . dpi = origDPI self . figure . set_facecolor ( origfacecolor ) self . figure . set_edgecolor ( origedgecolor ) self . figure . set_canvas ( self ) return result
Render the figure to hardcopy.
Render the figure to hardcopy .
"""
        Render the figure to hardcopy. Set the figure patch face and edge
        colors.  This is useful because some of the GUIs have a gray figure
        face color background and you'll probably want to override this on
        hardcopy.

        Arguments are:

        *filename*
            can also be a file object on image backends

        *orientation*
            only currently applies to PostScript printing.

        *dpi*
            the dots per inch to save the figure in; if None, use savefig.dpi

        *facecolor*
            the facecolor of the figure

        *edgecolor*
            the edgecolor of the figure

        *orientation*
            landscape' | 'portrait' (not supported on all backends)

        *format*
            when set, forcibly set the file format to save to


        *bbox_inches*
            Bbox in inches. Only the given portion of the figure is
            saved. If 'tight', try to figure out the tight bbox of
            the figure.

        *pad_inches*
            Amount of padding around the figure when bbox_inches is
            'tight'.

        *bbox_extra_artists*
            A list of extra artists that will be considered when the
            tight bbox is calculated.

        """ # call adjust_bbox to save only the given area # when bbox_inches == "tight", it saves the figure # twice. The first save command is just to estimate # the bounding box of the figure. A stringIO object is # used as a temporary file object, but it causes a # problem for some backends (ps backend with # usetex=True) if they expect a filename, not a # file-like object. As I think it is best to change # the backend to support file-like object, i'm going # to leave it as it is. However, a better solution # than stringIO seems to be needed. -JJL #self.figure.canvas.draw() ## seems superfluous
self
filename
dpi
facecolor
edgecolor
orientation
format