lib/matplotlib/backends/backend_ps.py
def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
                          orientation, isLandscape, papertype,
                          **kwargs):
        """
        If text.usetex is True in rc, a temporary pair of tex/eps files
        are created to allow tex to manage the text layout via the PSFrags
        package. These files are processed to yield the final ps or eps file.
        """
        isEPSF = format == 'eps'
        title = outfile

        # write to a temp file, we'll move it to outfile when done
        fd, tmpfile = mkstemp()
        os.close(fd)
        fh = file(tmpfile, 'w')

        self.figure.dpi = 72 # ignore the dpi kwarg
        width, height = self.figure.get_size_inches()
        xo = 0
        yo = 0

        l, b, w, h = self.figure.bbox.bounds
        llx = xo
        lly = yo
        urx = llx + w
        ury = lly + h
        bbox = (llx, lly, urx, ury)

        # generate PostScript code for the figure and store it in a string
        origfacecolor = self.figure.get_facecolor()
        origedgecolor = self.figure.get_edgecolor()
        self.figure.set_facecolor(facecolor)
        self.figure.set_edgecolor(edgecolor)

        dryrun = kwargs.get("dryrun", False)
        if dryrun:
            class NullWriter(object):
                def write(self, *kl, **kwargs):
                    pass

            self._pswriter = NullWriter()
        else:
            self._pswriter = StringIO()


        # mixed mode rendering
        _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
        ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
        renderer = MixedModeRenderer(self.figure,
            width, height, dpi, ps_renderer,
            bbox_inches_restore=_bbox_inches_restore)

        self.figure.draw(renderer)

        if dryrun: # return immediately if dryrun (tightbbox=True)
            return

        self.figure.set_facecolor(origfacecolor)
        self.figure.set_edgecolor(origedgecolor)

        # write the Encapsulated PostScript headers
        print >>fh, "%!PS-Adobe-3.0 EPSF-3.0"
        if title: print >>fh, "%%Title: "+title
        print >>fh, ("%%Creator: matplotlib version "
                     +__version__+", http://matplotlib.sourceforge.net/")
        print >>fh, "%%CreationDate: "+time.ctime(time.time())
        print >>fh, "%%%%BoundingBox: %d %d %d %d" % bbox
        print >>fh, "%%EndComments"

        Ndict = len(psDefs)
        print >>fh, "%%BeginProlog"
        print >>fh, "/mpldict %d dict def"%Ndict
        print >>fh, "mpldict begin"
        for d in psDefs:
            d=d.strip()
            for l in d.split('\n'):
                print >>fh, l.strip()
        print >>fh, "end"
        print >>fh, "%%EndProlog"

        print >>fh, "mpldict begin"
        #print >>fh, "gsave"
        print >>fh, "%s translate"%_nums_to_str(xo, yo)
        print >>fh, "%s clipbox"%_nums_to_str(width*72, height*72, 0, 0)

        # write the figure
        print >>fh, self._pswriter.getvalue()

        # write the trailer
        #print >>fh, "grestore"
        print >>fh, "end"
        print >>fh, "showpage"
        fh.close()

        if isLandscape: # now we are ready to rotate
            isLandscape = True
            width, height = height, width
            bbox = (lly, llx, ury, urx)

        # set the paper size to the figure size if isEPSF. The
        # resulting ps file has the given size with correct bounding
        # box so that there is no need to call 'pstoeps'
        if isEPSF:
            paperWidth, paperHeight = self.figure.get_size_inches()
            if isLandscape:
                paperWidth, paperHeight = paperHeight, paperWidth
        else:
            temp_papertype = _get_papertype(width, height)
            if papertype=='auto':
                papertype = temp_papertype
                paperWidth, paperHeight = papersize[temp_papertype]
            else:
                paperWidth, paperHeight = papersize[papertype]
                if (width>paperWidth or height>paperHeight) and isEPSF:
                    paperWidth, paperHeight = papersize[temp_papertype]
                    verbose.report('Your figure is too big to fit on %s paper. %s \
    paper will be used to prevent clipping.'%(papertype, temp_papertype), 'helpful')


        texmanager = ps_renderer.get_texmanager()
        font_preamble = texmanager.get_font_preamble()
        custom_preamble = texmanager.get_custom_preamble()

        convert_psfrags(tmpfile, ps_renderer.psfrag, font_preamble,
                        custom_preamble, paperWidth, paperHeight,
                        orientation)

        if rcParams['ps.usedistiller'] == 'ghostscript':
            gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
        elif rcParams['ps.usedistiller'] == 'xpdf':
            xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
        elif rcParams['text.usetex']:
            if False: pass # for debugging
            else: gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)

        if  isinstance(outfile, file):
            fh = file(tmpfile)
            print >>outfile, fh.read()
        else: shutil.move(tmpfile, outfile)

        If text.usetex is True in rc, a temporary pair of tex/eps files
        are created to allow tex to manage the text layout via the PSFrags
        package. These files are processed to yield the final ps or eps file.
        
If text.usetex is True in rc, a temporary pair of tex/eps files
are created to allow tex to manage the text layout via the PSFrags
package. These files are processed to yield the final ps or eps file.
If text . usetex is True in rc a temporary pair of tex / eps files are created to allow tex to manage the text layout via the PSFrags package . These files are processed to yield the final ps or eps file .
def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
                          orientation, isLandscape, papertype,
                          **kwargs):
        isEPSF = format == 'eps'
        title = outfile
        fd, tmpfile = mkstemp()
        os.close(fd)
        fh = file(tmpfile, 'w')
        self.figure.dpi = 72 
        width, height = self.figure.get_size_inches()
        xo = 0
        yo = 0
        l, b, w, h = self.figure.bbox.bounds
        llx = xo
        lly = yo
        urx = llx + w
        ury = lly + h
        bbox = (llx, lly, urx, ury)
        origfacecolor = self.figure.get_facecolor()
        origedgecolor = self.figure.get_edgecolor()
        self.figure.set_facecolor(facecolor)
        self.figure.set_edgecolor(edgecolor)
        dryrun = kwargs.get("dryrun", False)
        if dryrun:
            class NullWriter(object):
                def write(self, *kl, **kwargs):
                    pass
            self._pswriter = NullWriter()
        else:
            self._pswriter = StringIO()
        _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
        ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
        renderer = MixedModeRenderer(self.figure,
            width, height, dpi, ps_renderer,
            bbox_inches_restore=_bbox_inches_restore)
        self.figure.draw(renderer)
        if dryrun: 
            return
        self.figure.set_facecolor(origfacecolor)
        self.figure.set_edgecolor(origedgecolor)
        print >>fh, "%!PS-Adobe-3.0 EPSF-3.0"
        if title: print >>fh, "%%Title: "+title
        print >>fh, ("%%Creator: matplotlib version "
                     +__version__+", http://matplotlib.sourceforge.net/")
        print >>fh, "%%CreationDate: "+time.ctime(time.time())
        print >>fh, "%%%%BoundingBox: %d %d %d %d" % bbox
        print >>fh, "%%EndComments"
        Ndict = len(psDefs)
        print >>fh, "%%BeginProlog"
        print >>fh, "/mpldict %d dict def"%Ndict
        print >>fh, "mpldict begin"
        for d in psDefs:
            d=d.strip()
            for l in d.split('\n'):
                print >>fh, l.strip()
        print >>fh, "end"
        print >>fh, "%%EndProlog"
        print >>fh, "mpldict begin"
        print >>fh, "%s translate"%_nums_to_str(xo, yo)
        print >>fh, "%s clipbox"%_nums_to_str(width*72, height*72, 0, 0)
        print >>fh, self._pswriter.getvalue()
        print >>fh, "end"
        print >>fh, "showpage"
        fh.close()
        if isLandscape: 
            isLandscape = True
            width, height = height, width
            bbox = (lly, llx, ury, urx)
        if isEPSF:
            paperWidth, paperHeight = self.figure.get_size_inches()
            if isLandscape:
                paperWidth, paperHeight = paperHeight, paperWidth
        else:
            temp_papertype = _get_papertype(width, height)
            if papertype=='auto':
                papertype = temp_papertype
                paperWidth, paperHeight = papersize[temp_papertype]
            else:
                paperWidth, paperHeight = papersize[papertype]
                if (width>paperWidth or height>paperHeight) and isEPSF:
                    paperWidth, paperHeight = papersize[temp_papertype]
                    verbose.report('Your figure is too big to fit on %s paper. %s \
    paper will be used to prevent clipping.'%(papertype, temp_papertype), 'helpful')
        texmanager = ps_renderer.get_texmanager()
        font_preamble = texmanager.get_font_preamble()
        custom_preamble = texmanager.get_custom_preamble()
        convert_psfrags(tmpfile, ps_renderer.psfrag, font_preamble,
                        custom_preamble, paperWidth, paperHeight,
                        orientation)
        if rcParams['ps.usedistiller'] == 'ghostscript':
            gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
        elif rcParams['ps.usedistiller'] == 'xpdf':
            xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
        elif rcParams['text.usetex']:
            if False: pass 
            else: gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
        if  isinstance(outfile, file):
            fh = file(tmpfile)
            print >>outfile, fh.read()
        else: shutil.move(tmpfile, outfile)
def _print_figure_tex ( self , outfile , format , dpi , facecolor , edgecolor , orientation , isLandscape , papertype , ** kwargs ) : isEPSF = format == 'eps' title = outfile fd , tmpfile = mkstemp ( ) os . close ( fd ) fh = file ( tmpfile , 'w' ) self . figure . dpi = 72 width , height = self . figure . get_size_inches ( ) xo = 0 yo = 0 l , b , w , h = self . figure . bbox . bounds llx = xo lly = yo urx = llx + w ury = lly + h bbox = ( llx , lly , urx , ury ) origfacecolor = self . figure . get_facecolor ( ) origedgecolor = self . figure . get_edgecolor ( ) self . figure . set_facecolor ( facecolor ) self . figure . set_edgecolor ( edgecolor ) dryrun = kwargs . get ( "dryrun" , False ) if dryrun : class NullWriter ( object ) : def write ( self , * kl , ** kwargs ) : pass self . _pswriter = NullWriter ( ) else : self . _pswriter = StringIO ( ) _bbox_inches_restore = kwargs . pop ( "bbox_inches_restore" , None ) ps_renderer = RendererPS ( width , height , self . _pswriter , imagedpi = dpi ) renderer = MixedModeRenderer ( self . figure , width , height , dpi , ps_renderer , bbox_inches_restore = _bbox_inches_restore ) self . figure . draw ( renderer ) if dryrun : return self . figure . set_facecolor ( origfacecolor ) self . figure . set_edgecolor ( origedgecolor ) print >> fh , "%!PS-Adobe-3.0 EPSF-3.0" if title : print >> fh , "%%Title: " + title print >> fh , ( "%%Creator: matplotlib version " + __version__ + ", http://matplotlib.sourceforge.net/" ) print >> fh , "%%CreationDate: " + time . ctime ( time . time ( ) ) print >> fh , "%%%%BoundingBox: %d %d %d %d" % bbox print >> fh , "%%EndComments" Ndict = len ( psDefs ) print >> fh , "%%BeginProlog" print >> fh , "/mpldict %d dict def" % Ndict print >> fh , "mpldict begin" for d in psDefs : d = d . strip ( ) for l in d . split ( '\n' ) : print >> fh , l . strip ( ) print >> fh , "end" print >> fh , "%%EndProlog" print >> fh , "mpldict begin" print >> fh , "%s translate" % _nums_to_str ( xo , yo ) print >> fh , "%s clipbox" % _nums_to_str ( width * 72 , height * 72 , 0 , 0 ) print >> fh , self . _pswriter . getvalue ( ) print >> fh , "end" print >> fh , "showpage" fh . close ( ) if isLandscape : isLandscape = True width , height = height , width bbox = ( lly , llx , ury , urx ) if isEPSF : paperWidth , paperHeight = self . figure . get_size_inches ( ) if isLandscape : paperWidth , paperHeight = paperHeight , paperWidth else : temp_papertype = _get_papertype ( width , height ) if papertype == 'auto' : papertype = temp_papertype paperWidth , paperHeight = papersize [ temp_papertype ] else : paperWidth , paperHeight = papersize [ papertype ] if ( width > paperWidth or height > paperHeight ) and isEPSF : paperWidth , paperHeight = papersize [ temp_papertype ] verbose . report ( 'Your figure is too big to fit on %s paper. %s \
    paper will be used to prevent clipping.' % ( papertype , temp_papertype ) , 'helpful' ) texmanager = ps_renderer . get_texmanager ( ) font_preamble = texmanager . get_font_preamble ( ) custom_preamble = texmanager . get_custom_preamble ( ) convert_psfrags ( tmpfile , ps_renderer . psfrag , font_preamble , custom_preamble , paperWidth , paperHeight , orientation ) if rcParams [ 'ps.usedistiller' ] == 'ghostscript' : gs_distill ( tmpfile , isEPSF , ptype = papertype , bbox = bbox ) elif rcParams [ 'ps.usedistiller' ] == 'xpdf' : xpdf_distill ( tmpfile , isEPSF , ptype = papertype , bbox = bbox ) elif rcParams [ 'text.usetex' ] : if False : pass else : gs_distill ( tmpfile , isEPSF , ptype = papertype , bbox = bbox ) if isinstance ( outfile , file ) : fh = file ( tmpfile ) print >> outfile , fh . read ( ) else : shutil . move ( tmpfile , outfile )
If text.usetex is True in rc, a temporary pair of tex/eps files
are created to allow tex to manage the text layout via the PSFrags
package.
If text . usetex is True in rc a temporary pair of tex / eps files are created to allow tex to manage the text layout via the PSFrags package .
"""
        If text.usetex is True in rc, a temporary pair of tex/eps files
        are created to allow tex to manage the text layout via the PSFrags
        package. These files are processed to yield the final ps or eps file.
        """ # write to a temp file, we'll move it to outfile when done # ignore the dpi kwarg # generate PostScript code for the figure and store it in a string # mixed mode rendering # return immediately if dryrun (tightbbox=True) # write the Encapsulated PostScript headers #print >>fh, "gsave" # write the figure # write the trailer #print >>fh, "grestore" # now we are ready to rotate # set the paper size to the figure size if isEPSF. The # resulting ps file has the given size with correct bounding # box so that there is no need to call 'pstoeps' # for debugging
self
outfile
format
dpi
facecolor
edgecolor
orientation
isLandscape
papertype