def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w', orientation='portrait'): if DEBUG: print 'backend_cairo.FigureCanvasCairo.%s()' % _fn_name() # settings for printing figure.dpi.set(dpi) figure.set_facecolor(facecolor) figure.set_edgecolor(edgecolor) if isinstance(filename, file): # eg when do savefig(sys.stdout) _save_png (figure, filename) # assume PNG format else: root, ext = os.path.splitext(filename) ext = ext[1:] if ext == '': ext = IMAGE_FORMAT_DEFAULT filename = filename + '.' + ext ext = ext.lower() if ext in ('png', 'ps'): # native formats try: fileObject = file(filename,'wb') except IOError, exc: verbose.report_error("%s: %s" % (exc.filename, exc.strerror)) else: if ext == 'png': _save_png (figure, fileObject) else: _save_ps (figure, fileObject, orientation) elif ext in ('eps', 'svg'): # backend_svg/ps if ext == 'svg': from backend_svg import FigureCanvasSVG as FigureCanvas else: from backend_ps import FigureCanvasPS as FigureCanvas fc = FigureCanvas(figure) fc.print_figure(filename, dpi, facecolor, edgecolor, orientation)
def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w', orientation='portrait'): if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name()) # settings for printing self.figure.dpi.set(dpi) self.figure.set_facecolor(facecolor) self.figure.set_edgecolor(edgecolor) # if isinstance(filename, file): # eg when do savefig(sys.stdout) # _save_png (self.figure, filename) # assume PNG format # else: if True: root, ext = os.path.splitext(filename) ext = ext[1:] if ext == '': ext = IMAGE_FORMAT_DEFAULT filename = filename + '.' + ext ext = ext.lower() if ext in ('pdf', 'png', 'ps'): # native formats # try: # fileObject = file(filename,'wb') # except IOError, exc: # warnings.warn("%s: %s" % (exc.filename, exc.strerror)) # else: # if ext == 'png': _save_png (fileObject) if ext == 'png': self._save_png(filename) # else: _save_ps_pdf (self.figure, fileObject, ext, # orientation) else: self._save_ps_pdf(self.figure, filename, ext, orientation) # fileObject.close() elif ext in ('eps', 'svg'): # backend_svg/ps if ext == 'svg': from backend_svg import FigureCanvasSVG as FigureCanvas else: from backend_ps import FigureCanvasPS as FigureCanvas fc = FigureCanvas(self.figure) fc.print_figure(filename, dpi, facecolor, edgecolor, orientation) else: warnings.warn('Format "%s" is not supported.\n' 'Supported formats: ' '%s.' % (ext, ', '.join(IMAGE_FORMAT)))