Changeset 5646


Ignore:
Timestamp:
20/08/09 12:06:47 (10 years ago)
Author:
pnorton
Message:

Added the ability to draw a plot directly to a string buffer rather than to a file. There are still some problems with this method, currently the logo isn't included and it cannot cope with 'jpg' outputs.

Location:
qesdi/geoplot/trunk/lib/geoplot
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • qesdi/geoplot/trunk/lib/geoplot/config.ini

    r5610 r5646  
    5757metadataFrameColour='0.75' 
    5858 
    59 logoPath=/home/users/pnorton/svn/qesdi/geoplot_trunk/data/logo.png 
    60 EPSLogoPathRGB=/home/users/pnorton/svn/qesdi/geoplot/trunk/data/logo.eps 
     59logoPath        = /home/users/pnorton/svn/qesdi/geoplot_trunk/data/logo.png 
     60EPSLogoPathRGB  = /home/users/pnorton/svn/qesdi/geoplot_trunk/data/logo.eps 
    6161 
    6262EPSLogoPathCMYK=style/logo_cmyk.eps 
  • qesdi/geoplot/trunk/lib/geoplot/plot_base.py

    r5612 r5646  
    157157    def drawToImage(self): 
    158158        if self.format not in 'png': 
    159             raise Exception("format %s not yet supported for image retrival" % (self.format,)) 
     159            raise Exception("format %s not yet supported for image retrieval" % (self.format,)) 
    160160         
    161161        self._drawToPlotArea() 
     
    165165        return im         
    166166     
     167    def drawToBuffer(self): 
     168        self._drawToPlotArea() 
     169        return self._plotWriter.printFigureToBuffer(self._plotArea.figure) 
     170         
     171         
     172         
    167173    def _drawDiagram(self, *args, **kwargs): 
    168174        raise NotImplementedError() 
  • qesdi/geoplot/trunk/lib/geoplot/plot_writer.py

    r5605 r5646  
    99import time 
    1010 
     11import StringIO 
    1112import logging 
    1213 
    1314from matplotlib.backends.backend_agg import FigureCanvasAgg 
    1415from matplotlib.backends.backend_ps import FigureCanvasPS 
     16from matplotlib.backends.backend_pdf import FigureCanvasPdf 
     17from matplotlib.backends.backend_svg import FigureCanvasSVG 
    1518 
    1619 
     
    222225        os.rename(outputFile, filename) 
    223226 
     227    def printFigureToBuffer(self, figure): 
     228        """ 
     229        Plots the figure directly to StringIO buffer 
     230        """ 
     231         
     232        buffer = StringIO.StringIO() 
     233        self._printFigure(buffer, figure) 
     234        buffer.seek(0) 
     235         
     236        return buffer       
     237 
    224238    def _printFigure(self, filename, figure): 
    225239        """ 
     
    234248 
    235249        """ 
    236         froot, ext = os.path.splitext(filename) 
    237  
    238         if ext == '.ps': 
     250 
     251        if self.format == 'ps': 
    239252            CanvasClass=FigureCanvasPS 
    240         elif ext == '.png': 
     253        elif self.format == 'png': 
    241254            CanvasClass=FigureCanvasAgg 
    242         else: 
    243             raise Exception("Unknown format to write to , " + ext) 
     255        elif self.format == 'pdf': 
     256            CanvasClass=FigureCanvasPdf 
     257        elif self.format == 'svg': 
     258            CanvasClass = FigureCanvasSVG 
     259        else: 
     260            raise Exception("Unknown format to write to , " + self.format) 
    244261 
    245262        canvas = CanvasClass(figure) 
    246263 
    247         return canvas.print_figure(filename, dpi=figure.get_dpi()) 
     264        return canvas.print_figure(filename,  
     265                                   dpi=figure.get_dpi(), 
     266                                   facecolor=figure.get_facecolor(),  
     267                                   edgecolor=figure.get_edgecolor()) 
     268     
     269     
     270     
Note: See TracChangeset for help on using the changeset viewer.