def on_savefig ( self ):
        """ Handles the user requesting that the image of the function is to be saved.
        """
        import os
        dlg = FileDialog(parent = self.control, 
                         title = 'Save as image',
                         default_directory=os.getcwd(),
                         default_filename="", wildcard=WILDCARD,
                         action='save as')
        if dlg.open() == OK:
            path = dlg.path

            print "Saving plot to", path, "..."
            try:

                # Now we create a canvas of the appropriate size and ask it to render
                # our component.  (If we wanted to display this plot in a window, we
                # would not need to create the graphics context ourselves; it would be
                # created for us by the window.)
                self._plot.bounds = [500,300]
                self._plot.padding = 50
                plot_gc = PlotGraphicsContext(self._plot.outer_bounds)
                print self._plot.outer_bounds
                plot_gc.render_component(self._plot)

                # Finally, we tell the graphics context to save itself to disk as an image.
                plot_gc.save(path)
                
            except:
                print "Error saving!"
                raise
            print "Plot saved."
        return
    def on_savefig ( self ):
        """ Handles the user requesting that the image of the function is to be saved.
        """
        import os
        dlg = FileDialog(parent = self.control, 
                         title = 'Save as image',
                         default_directory=os.getcwd(),
                         default_filename="", wildcard=WILDCARD,
                         action='save as')
        if dlg.open() == OK:
            path = dlg.path

            print "Saving plot to", path, "..."
            try:

                # Now we create a canvas of the appropriate size and ask it to render
                # our component.  (If we wanted to display this plot in a window, we
                # would not need to create the graphics context ourselves; it would be
                # created for us by the window.)

               # plot_gc = PlotGraphicsContext(self._plot.outer_bounds)
               # plot_gc.render_component(self._plot)
                              
                #self._plot_container.outer_bounds = list((800,600))
#                plot_gc = PlotGraphicsContext((400,300), dpi=72.0)
#                plot_gc.render_component(self._plot_container)

#                self.line_plot.bounds = [500,300]
#                self.line_plot.padding = 50
#
#                win_size = self.line_plot.outer_bounds
#             #   win_size = self.component.outer_bounds
#                plot_gc = PlotGraphicsContext(win_size)
#        
#        
#                # Have the plot component into it
#                plot_gc.render_component(self.line_plot)
#
#                # Finally, we tell the graphics context to save itself to disk as an image.
#                plot_gc.save(path)

                DPI = 70.0
                size=(550,450)
             #   self.plot_container = create_plot()
                self.plot_container.bounds = list(size)
                self.plot_container.do_layout(force=True)
                
                gc = PlotGraphicsContext(size, dpi=DPI)
               

                #gc = GraphicsContext((size[0]+1, size[1]+1))
                gc.render_component(self.plot_container)
                gc.save(path)

                
            except:
                print "Error saving!"
                raise
            print "Plot saved."
        return
def draw_plot(filename, size=(800,600)):
    container = create_plot()
    container.outer_bounds = list(size)
    container.do_layout(force=True)
    gc = PlotGraphicsContext(size, dpi=DPI)
    gc.render_component(container)
    gc.save(filename)
    return
示例#4
0
 def _save_raster(self):
     """ Saves an image of the component.
     """
     from enthought.chaco.api import PlotGraphicsContext
     gc = PlotGraphicsContext((int(self.component.outer_width), int(self.component.outer_height)))
     self.component.draw(gc, mode="normal")
     gc.save(self.filename)
     return
示例#5
0
 def _save_raster(self):
     """ Saves an image of the component.
     """
     from enthought.chaco.api import PlotGraphicsContext
     gc = PlotGraphicsContext((int(self.component.outer_width),
                               int(self.component.outer_height)))
     self.component.draw(gc, mode="normal")
     gc.save(self.filename)
     return
示例#6
0
    def _save(self):
        # Create a graphics context of the right size
        win_size = self.plot.outer_bounds
        plot_gc = PlotGraphicsContext(win_size)

        # Have the plot component into it
        plot_gc.render_component(self.plot)

        # Save out to the user supplied filename
        plot_gc.save(self._save_file)
示例#7
0
 def save_plot(self):
     from easygui import filesavebox
     file_string=str(self.file_name.rstrip('.npy')+'.png')
     tmp = filesavebox(title = "Save to", default=file_string)
     if tmp:
         try:
             self._save_file = tmp + '.png'
             win_size = self.plot.outer_bounds
             plot_gc = PlotGraphicsContext(win_size)
             plot_gc.render_component(self.plot)
             plot_gc.save(self._save_file)
         except:
             print 'Saving failed'
def draw_plot(filename, size=(800, 600), num_plots=8, type="line", key=""):
    """ Save the plot, and generate the hover_data file. """
    container = create_plot(num_plots, type)
    container.outer_bounds = list(size)
    container.do_layout(force=True)
    gc = PlotGraphicsContext(size, dpi=DPI)
    gc.render_component(container)
    if filename:
        gc.save(filename)
        script_filename = filename[:-4] + "_png_hover_data.js"
    else:
        script_filename = None
    plot = make_palettized_png_str(gc)
    script_data = write_hover_coords(container, key, script_filename)
    return (plot, script_data)
示例#9
0
    def test_draw_border_simple(self):
        """ Borders should have the correct height and width.
        """
        size = (5,5)
        container = Plot(padding=1, border_visible=True)
        container.outer_bounds = list(size)
        gc = PlotGraphicsContext(size)
        gc.render_component(container)

        desired = array(((255, 255, 255, 255, 255, 255),
                         (255, 255, 255, 255, 255, 255),
                         (255,   0,   0,   0, 255, 255),
                         (255,   0, 255,   0, 255, 255),
                         (255,   0,   0,   0, 255, 255),
                         (255, 255, 255, 255, 255, 255)))

        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(actual, desired)