def _SaveFlag_changed(self): DPI = 72 print '--------------Save Initiated------------------' #Main plot save code size = (self.IntensityData[:,:,self.intensityindex].shape[0]*4, self.IntensityData[:,:,self.intensityindex].shape[1]*4) path = os.getenv('PWD') filenamelist = [path, '/', 'MainPlot_WaveLen', str(self.Wavelength).replace('.','_'), '.png'] filename = ''.join(filenamelist) container = self.Main_img_plot temp = container.outer_bounds container.outer_bounds = list(size) container.do_layout(force=True) gc = PlotGraphicsContext(size, dpi=DPI) gc.render_component(container) gc.save(filename) container.outer_bounds = temp print "SAVED: ", filename #Spectra plot save code size = (1000,500) path = os.getenv('PWD') filenamelist = [path, '/', 'SpectraPlot_X', str(self.InspectorPosition[0]), '_Y', str(self.InspectorPosition[1]), '.png'] filename = ''.join(filenamelist) container = self.Spectraplot1 temp = container.outer_bounds container.outer_bounds = list(size) container.do_layout(force=True) gc = PlotGraphicsContext(size, dpi=DPI) gc.render_component(container) gc.save(filename) container.outer_bounds = temp print "SAVED: ", filename return
def save(self): """ Show a dialog for saving the figure. Return whether the figure was successfully saved. """ name_filters, selected_name_filter = file_type_filters( self.save_formats, default=self.default_save_format) filename = FileDialogEx.get_save_file_name( parent=self, name_filters=name_filters, selected_name_filter=selected_name_filter) if filename: gc = PlotGraphicsContext((int(self.component.outer_width), int(self.component.outer_height))) self.component.draw(gc, mode="normal") try: gc.save(filename) except Exception as exc: warning(parent=self.parent, title='Save Error', text='Error saving figure', content=str(exc)) else: return True return False
def OnMenuExportPNG(self, e=None): """ Saves plot container as png """ dlg = wx.FileDialog(self, "Export plot as PNG", self.config.GetWorkingDirectory("PNG"), "", "PDF file (*.png)|*.png", wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() if not path.endswith(".png"): path += ".png" self.config.SetWorkingDirectory(os.path.dirname(path), "PNG") container = self.PlotArea.mainplot.container # get inner_boundary p = container dpi=600 p.do_layout(force=True) gc = PlotGraphicsContext(tuple(p.outer_bounds), dpi=dpi) # temporarily turn off the backbuffer for offscreen rendering use_backbuffer = p.use_backbuffer p.use_backbuffer = False p.draw(gc) #gc.render_component(p) gc.save(path) p.use_backbuffer = use_backbuffer
def OnMenuExportPNG(self, e=None): """ Saves plot container as png """ dlg = wx.FileDialog(self, "Export plot as PNG", self.config.GetWorkingDirectory("PNG"), "", "PDF file (*.png)|*.png", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() if not path.endswith(".png"): path += ".png" self.config.SetWorkingDirectory(os.path.dirname(path), "PNG") container = self.PlotArea.mainplot.container # get inner_boundary p = container dpi = 600 p.do_layout(force=True) gc = PlotGraphicsContext(tuple(p.outer_bounds), dpi=dpi) # temporarily turn off the backbuffer for offscreen rendering use_backbuffer = p.use_backbuffer p.use_backbuffer = False p.draw(gc) #gc.render_component(p) gc.save(path) p.use_backbuffer = use_backbuffer
def export_image(self, fname, size=(800,600)): """Save plot as png image.""" # self.outer_bounds = list(size) # self.do_layout(force=True) gc = PlotGraphicsContext(self.outer_bounds) gc.render_component(self) gc.save(fname, file_format=None)
def save_plot(plot, filename, width, height): plt_bounds = plot.outer_bounds plot.do_layout(force=True) gc = PlotGraphicsContext(plt_bounds, dpi=72) gc.render_component(plot) gc.save(filename) print "Plot saved to: ", filename
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
def _save_raster(self): """ Saves an image of the component. """ from 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
def save_plot(plot, filename, width, height): # http://docs.enthought.com/chaco/user_manual/how_do_i.html from chaco.api import PlotGraphicsContext plot.outer_bounds = [width, height] plot.do_layout(force=True) gc = PlotGraphicsContext((width, height), dpi=72) gc.render_component(plot) gc.save(filename)
def _save_raster(self): ''' Saves an image of the component. ''' from 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
def plotRU(self, rangeX=None, rangeY=None, save=False, filename=""): if save and filename == "": self.add_line("ERROR: I need a valid file name") return if save and filename.split('.')[-1] != "png": self.add_line("ERROR: File must end in .png") return if len(self.morseList) > 0: plotData = ArrayPlotData(x=self.Rlist, y=self.Ulist, morse=self.morseList, eigX=[self.Rlist[0], self.Rlist[-1]]) else: plotData = ArrayPlotData(x=self.Rlist, y=self.Ulist) for val in self.levelsToFind: if val < len(self.convergedValues): plotData.set_data( "eig" + str(val), [self.convergedValues[val], self.convergedValues[val]]) plot = Plot(plotData) if len(self.morseList) > 0: plot.plot(("x", "morse"), type="line", color="red") for val in self.levelsToFind: if val < len(self.convergedValues): plot.plot(("eigX", "eig" + str(val)), type="line", color="green") plot.plot(("x", "y"), type="line", color="blue") plot.plot(("x", "y"), type="scatter", marker_size=1.0, color="blue") # plot.index_axis.title = "Separation (r0)" if (self.scaled): plot.value_axis.title = "Potential (Eh * 2 * mu)" else: plot.value_axis.title = "Potential (Eh)" if len(self.plotRangeX) != 0: plot.x_axis.mapper.range.low = self.plotRangeX[0] plot.x_axis.mapper.range.high = self.plotRangeX[1] if len(self.plotRangeY) != 0: plot.y_axis.mapper.range.low = self.plotRangeY[0] plot.y_axis.mapper.range.high = self.plotRangeY[1] if not save: self.plot = plot else: plot.outer_bounds = [800, 600] plot.do_layout(force=True) gc = PlotGraphicsContext((800, 600), dpi=72) gc.render_component(plot) gc.save(filename)
def _save_plot(self, plot, filename, width=800, height=600, dpi=72): self.set_plot_title(plot, self.plot_title) original_outer_bounds = plot.outer_bounds plot.outer_bounds = [width, height] plot.do_layout(force=True) gc = PlotGraphicsContext((width, height), dpi=dpi) gc.render_component(plot) gc.save(filename) plot.outer_bounds = original_outer_bounds
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)
def save_raster(self, filename): """ Saves an image of a chaco component (e.g. 'Plot' or 'Container') to a raster file, such as .jpg or .png. The file type is terermined by the extension. """ from chaco.api import PlotGraphicsContext gc = PlotGraphicsContext(self.outer_bounds, dpi=72) self.draw(gc, mode="normal") #gc.render_component(self) gc.save(filename) return
def save_plot(self, filename=None): ''' Saves an image of the component. ''' if filename is None: filename = 'plots/plot%05d.jpg' %(round(self.time/self.delay*self.time_factor)) d = os.path.dirname(filename) if d != '' and not os.path.exists(d): os.makedirs(os.path.dirname(filename)) gc = PlotGraphicsContext((int(self.component.outer_width), int(self.component.outer_height))) self.component.draw(gc, mode="normal") gc.save(filename)
def plotRU(self,rangeX=None, rangeY=None, save=False, filename=""): if save and filename == "": self.add_line("ERROR: I need a valid file name") return if save and filename.split('.')[-1] != "png": self.add_line("ERROR: File must end in .png") return if len(self.morseList) > 0: plotData = ArrayPlotData(x=self.Rlist, y=self.Ulist, morse=self.morseList, eigX=[self.Rlist[0], self.Rlist[-1]]) else: plotData = ArrayPlotData(x=self.Rlist, y=self.Ulist) for val in self.levelsToFind: if val < len(self.convergedValues): plotData.set_data("eig"+str(val), [self.convergedValues[val], self.convergedValues[val]]) plot = Plot(plotData) if len(self.morseList) > 0: plot.plot(("x","morse"), type = "line", color = "red") for val in self.levelsToFind: if val < len(self.convergedValues): plot.plot(("eigX","eig"+str(val)), type="line", color="green") plot.plot(("x","y"), type = "line", color = "blue") plot.plot(("x","y"), type = "scatter", marker_size = 1.0, color = "blue") # plot.index_axis.title = "Separation (r0)" if (self.scaled): plot.value_axis.title = "Potential (Eh * 2 * mu)" else: plot.value_axis.title = "Potential (Eh)" if len(self.plotRangeX) != 0: plot.x_axis.mapper.range.low = self.plotRangeX[0] plot.x_axis.mapper.range.high = self.plotRangeX[1] if len(self.plotRangeY) != 0: plot.y_axis.mapper.range.low = self.plotRangeY[0] plot.y_axis.mapper.range.high = self.plotRangeY[1] if not save: self.plot = plot else: plot.outer_bounds = [800,600] plot.do_layout(force=True) gc = PlotGraphicsContext((800,600), dpi = 72) gc.render_component(plot) gc.save(filename)
def save_figure(self, figure, filename): """ Saves a figure as graphics file, e.g. .png. Example of usage: plot = my_instance.line_plot filename = 'foo.png' my_instance.save_figure(plot, filename) """ gc = PlotGraphicsContext(figure.outer_bounds, dpi=72) gc.render_component(figure) gc.save(filename)
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) # 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.lplot.bounds = [500, 300] self.lplot.padding = 50 win_size = self.lplot.outer_bounds plot_gc = PlotGraphicsContext(win_size) # Have the plot component into it plot_gc.render_component(self.lplot) # 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.) """ # self._plot.bounds = [500,300] # self._plot.padding = 50 # 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.lplot.bounds = [500, 300] self.lplot.padding = 50 win_size = self.lplot.outer_bounds plot_gc = PlotGraphicsContext(win_size) # Have the plot component into it plot_gc.render_component(self.lplot) # 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 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)
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)
def _png_export_fired(self): outfileName = self._getFilePath(defFileName=self.__DEF_FILE_NAME + '.png') if outfileName != None: from chaco.api import PlotGraphicsContext container = self.plot tempSize = copy.deepcopy( container.outer_bounds ) container.outer_bounds = list((self.width-1,self.height-1)) container.do_layout(force=True) # gc = PlotGraphicsContext((self.width,self.height), dpi=self.dpi) gc = PlotGraphicsContext((self.width-1,self.height-1)) gc.render_component(container) gc.save( outfileName ) container.outer_bounds = tempSize self.plot.request_redraw()
def _SaveFlag_changed(self): DPI = 72 #Main plot save code size = (1000,1000) path = os.getenv('PWD') filenamelist = [path, '/', 'SourcePlots_X', str(self.InspectorPosition[0]), '_Y', str(self.InspectorPosition[1]), '.png'] filename = ''.join(filenamelist) container = self.PrimaryPlotC temp = container.outer_bounds container.outer_bounds = list(size) container.do_layout(force=True) gc = PlotGraphicsContext(size, dpi=DPI) gc.render_component(container) gc.save(filename) container.outer_bounds = temp print "SAVED: ", filename
def _export_fired(self): dialog = FileDialog(action="save as", wildcard='.dat') dialog.open() if dialog.return_code == OK: # prepare plot for saving width = 800 height = 600 self.plot.outer_bounds = [width, height] self.plot.do_layout(force=True) gc = PlotGraphicsContext((width, height), dpi=72) gc.render_component(self.plot) #save data,image,description timetag = "" #init empty str for later directory = dialog.directory t = self.acqtime #retrieve time from last aquisition timelist = [t.tm_year,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec] timelist = map(str,timelist) #convert every entry to str of timelist for i in range(len(timelist)): #if sec is eg "5" change to "05" if len(timelist[i]) == 1: timelist[i] = "0" + timelist[i] timetag = timetag.join(timelist) #make single str of all entries filename = timetag + dialog.filename # join timetag and inidivid. name print "target directory: " + directory gc.save(filename+".png") self.wvl = self.create_wavelength_for_plotting() x,y = self.icCryo.pos() #get cryo pos pos = "Cryo was at pos "+ str(x) + " x " + str(y)+" y" with open(filename+'.dat','wb') as f: f.write('#'+ str(pos)+ '\n'+ '#\n'+ '#\n'+ '#\n') #this is for the header np.savetxt(f, np.transpose([self.wvl,self.line]), delimiter='\t')
def snapshot(self, params): gc = PlotGraphicsContext(self.conn_mat.outer_bounds, dpi=params.dpi) gc.render_component(self.conn_mat) gc.save(params.savefile)
def save_plot_img(component, filename, size, dpi=72): gc = PlotGraphicsContext(size, dpi=dpi) gc.render_component(component) gc.save(filename)
def _save(self): win_size = self.plot.outer_bounds plot_gc = PlotGraphicsContext(win_size) #, dpi=300) plot_gc.render_component(self.plot) plot_gc.save("image_test.png")
class PoincarePlotFastMovieMakerWorker(object): """ special fast movie generation class which uses chaco library """ def __init__(self, pp_specs_manager): self.manager = pp_specs_manager self.pp_specs = self.manager.getMiniPoincarePlotSpecs() if len(self.pp_specs) == 0: return self.gc = None self.p0 = self.pp_specs[0] #set up specific values for fonts sizes based on products of a movie #height and arbitrary constants to give looking good picture if self.manager.movie_axis_font == None: self.axis_font = 'modern ' + str(nvl_and_positive( self.manager.movie_axis_font_size, self.manager.movie_height / 38)) else: self.axis_font = self.manager.movie_axis_font if self.manager.movie_title_font == None: self.title_font = 'modern ' + str(nvl_and_positive( self.manager.movie_title_font_size, self.manager.movie_height / 30)) else: self.title_font = self.manager.movie_title_font self.time_label_font = 'modern ' + str(nvl_and_positive( self.manager.movie_time_label_font_size, self.manager.movie_height / 35)) self.tick_font = nvl(self.manager.movie_tick_font, None) self.frame_pad = nvl_and_positive(self.manager.movie_frame_pad, 50) def initiate(self): if len(self.pp_specs) == 0: return False # only positive values are accepted x = self.p0.x_data[pl.where(self.p0.x_data > 0)] y = self.p0.y_data[pl.where(self.p0.y_data > 0)] x_min = pl.amin(x) x_max = pl.amax(x) y_min = pl.amin(y) y_max = pl.amax(y) value_min = x_min if x_min < y_min else y_min self.value_max = x_max if x_max > y_max else y_max self.pd = ArrayPlotData() self.pd.set_data("index", x) self.pd.set_data("value", y) index_ds = ArrayDataSource(x) value_ds = ArrayDataSource(y) # Create the plot self._plot = Plot(self.pd) axis_defaults = { #'axis_line_weight': 2, #'tick_weight': 2, #'tick_label_color': 'green', 'title_font': self.axis_font, } if self.tick_font: axis_defaults['tick_label_font'] = self.tick_font #a very important and weird trick; used to remove default ticks labels self._plot.x_axis = None self._plot.y_axis = None #end trick #add new x label and x's ticks labels x_axis = PlotAxis(orientation='bottom', title=nvl(self.manager.x_label, 'RR(n) [ms]'), mapper=self._plot.x_mapper, **axis_defaults) self._plot.overlays.append(x_axis) #add new y label and y's ticks labels y_axis = PlotAxis(orientation='left', title=nvl(self.manager.y_label, 'RR(n+1) [ms]'), mapper=self._plot.y_mapper, **axis_defaults) self._plot.overlays.append(y_axis) self._plot.index_range.add(index_ds) self._plot.value_range.add(value_ds) self._plot.index_mapper.stretch_data = False self._plot.value_mapper.stretch_data = False self._plot.value_range.set_bounds(value_min, self.value_max) self._plot.index_range.set_bounds(value_min, self.value_max) # Create the index and value mappers using the plot data ranges imapper = LinearMapper(range=self._plot.index_range) vmapper = LinearMapper(range=self._plot.value_range) color = "white" self.scatter = __PoincarePlotScatterPlot__( self.p0, self.manager, index=index_ds, value=value_ds, #color_data=color_ds, #color_mapper=color_mapper, #fill_alpha=0.4, color=color, index_mapper=imapper, value_mapper=vmapper, marker='circle', marker_size=self.manager.active_point_size, line_width=0 #outline_color='white' ) self._plot.add(self.scatter) #self._plot.plots['var_size_scatter'] = [self.scatter] # Tweak some of the plot properties _title = nvl(self.manager.movie_title, "Poincare plot") if len(_title) > 0: self._plot.title = _title self._plot.title_font = self.title_font self._plot.line_width = 0.5 self._plot.padding = self.frame_pad self._plot.do_layout(force=True) self._plot.outer_bounds = [self.manager.movie_width, self.manager.movie_height] self.gc = PlotGraphicsContext(self._plot.outer_bounds, dpi=self.manager.movie_dpi) self.gc.render_component(self._plot) self.gc.set_line_width(0) self.gc.save(self._get_filename(self.p0)) self.x_mean_old = None self.y_mean_old = None self._time_label_font = None return True def plot(self, idx): if len(self.pp_specs) == 0: return p = self.pp_specs[idx] p_old = None if idx == 0 else self.pp_specs[idx - 1] if idx > 0: self.gc.set_line_width(0) if not p_old == None and not p_old.mean_plus == None: r_points = pl.array([[p_old.mean_plus, p_old.mean_minus]]) r_points = self.scatter.map_screen(r_points) self.gc.set_fill_color((1.0, 1.0, 1.0, 1.0)) self.gc.draw_marker_at_points(r_points, self.manager.centroid_point_size, CIRCLE) __update_graphics_context__(self.gc, self.scatter, p, self.manager) r_points = pl.array([[p.mean_plus, p.mean_minus]]) r_points = self.scatter.map_screen(r_points) self.gc.set_fill_color(self.manager.centroid_color_as_tuple) self.gc.draw_marker_at_points(r_points, self.manager.centroid_point_size, CIRCLE) #self.gc.save_state() self._draw_time_text(self.gc, p) self.gc.save_state() if self.manager.movie_frame_step > 0 and idx > 0: # only frames module movie_frame_step are generated if not self.manager.movie_frame_step % idx == 0: return if self.manager.movie_identity_line: __draw_identity_line__(self.gc, self.value_max, self.scatter) self.gc.save(self._get_filename(p)) def _draw_time_text(self, gc, pp_spec): if self.manager.movie_create_time_label == False: return if pp_spec.level == 0: (H, M, S) = get_time_label_parts_for_miliseconds(0, hour_label=self.manager.movie_hour_label, minute_label=self.manager.movie_minute_label, second_label=self.manager.movie_second_label) else: (H, M, S) = get_time_label_parts_for_miliseconds( pp_spec.cum_inactive, hour_label=self.manager.movie_hour_label, minute_label=self.manager.movie_minute_label, second_label=self.manager.movie_second_label) if not self._time_label_font: self._time_label_font = str_to_font(None, None, self.time_label_font) gc.set_font(self._time_label_font) shift = 10 if self.manager.movie_time_label_in_line == True: if self.manager.movie_time_label_prefix: time_line = '%s %s %s %s' % (self.manager.movie_time_label_prefix, H, M, S) else: time_line = '%s %s %s' % (H, M, S) _, _, tw, th = gc.get_text_extent(time_line) x = self._plot.outer_bounds[0] / 2 - tw / 2 - self._plot.padding_left y = self._plot.outer_bounds[1] - self._plot.padding_top - th gc.set_fill_color((1.0, 1.0, 1.0, 1.0)) gc.rect(x, y, tw, th + shift) gc.draw_path() gc.set_fill_color((0.0, 0.0, 0.0, 1.0)) gc.show_text_at_point(time_line, x, y) else: for idx, time_e in enumerate([H, M, S]): _, _, tw, th = gc.get_text_extent(time_e) x = self._plot.outer_bounds[0] - tw - self._plot.padding_right y = self._plot.outer_bounds[1] / 2 - idx * (th + shift) gc.set_fill_color((1.0, 1.0, 1.0, 1.0)) #gc.rect(x, y, tw + shift, th) gc.rect(x, y, tw, th + shift) gc.draw_path() gc.set_fill_color((0.0, 0.0, 0.0, 1.0)) gc.show_text_at_point(time_e, x, y) return def _get_filename(self, pp_spec): if self.manager.movie_frame_filename_with_time: (H, M, S) = get_time_for_miliseconds(0 if pp_spec.level == 0 else pp_spec.cum_inactive) if pp_spec.frame_file.endswith(PNG_EXTENSION): filename = pp_spec.frame_file.rsplit(PNG_EXTENSION)[0] return '%s_%02d_%02d_%02d%s' % (filename, H, M, S, PNG_EXTENSION) return pp_spec.frame_file
def _save(self): win_size = self.plot.outer_bounds plot_gc = PlotGraphicsContext(win_size) plot_gc.render_component(self.plot) plot_gc.save(self._save_file)
def snapshot(self,params): gc=PlotGraphicsContext(self.conn_mat.outer_bounds,dpi=params.dpi) gc.render_component(self.conn_mat) gc.save(params.savefile)
def _save(self): win_size = self.plot.outer_bounds plot_gc = PlotGraphicsContext(win_size)#, dpi=300) plot_gc.render_component(self.plot) plot_gc.save("image_test.png")
def render_agg(): gc2 = PlotGraphicsContext((800,600), dpi=DPI) gc2.render_component(container) gc2.save("/tmp/kiva_agg.png")
def save_renderer_result(renderer, filename): renderer.padding = 0 gc = PlotGraphicsContext(renderer.outer_bounds) with gc: gc.render_component(renderer) gc.save(filename)
from chaco.pdf_graphics_context import PdfPlotGraphicsContext from chaco.tools.api import SaveTool data = {"x": [1, 2, 3, 4, 5], "y": [1, 2, 3, 2, 1]} plot = Plot(ArrayPlotData(**data)) plot.plot(("x", "y"), type="scatter", color="blue") plot.padding = 20 plot.outer_bounds = (800, 600) plot.do_layout(force=True) gc = PlotGraphicsContext((800, 600), dpi=72) gc.render_component(plot, container_coords=(10, 10)) gc.save("test1.PNG") # save_plot_to_file(plot, "test1.PNG") # save_plot_to_file(plot, "test2.PNG") # gc = PlotGraphicsContext((800, 600), dpi=72) # plot.draw(gc) # gc.save("test1.JPG") # gc = PdfPlotGraphicsContext(filename="test1.PDF", # pagesize="letter", # dest_box=(0.5, 0.5, -0.5, -0.5), # dest_box_units="inch") # gc.render_component(plot) # gc.save()