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_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_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 test_scatter_1d_selection(self): self.scatterplot.index.metadata['selections'] = [ (arange(10) % 2 == 0), ] gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
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 test_scatter_1d(self): self.assertEqual(self.scatterplot.origin, 'bottom left') self.assertIsNone(self.scatterplot.x_mapper) self.assertEqual(self.scatterplot.y_mapper, self.scatterplot.index_mapper) gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_1d_selection_mask_name(self): # select with a mask self.scatterplot.selection_metadata_name = 'highlight_masks' self.scatterplot.index.metadata['highlight_masks'] = [ (arange(10) % 2 == 0), ] gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_fast(self): """ Coverage test to check basic case works """ size = (50, 50) scatterplot = create_scatter_plot( data=[range(10), range(10)], border_visible=False, ) scatterplot.outer_bounds = list(size) gc = PlotGraphicsContext(size) gc.render_component(scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
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 test_scatter_circle(self): """ Coverage test to check circles work """ size = (50, 50) scatterplot = create_scatter_plot( data=[list(sm.xrange(10)), list(sm.xrange(10))], marker="circle", border_visible=False, ) scatterplot.outer_bounds = list(size) gc = PlotGraphicsContext(size) gc.render_component(scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_1d_horizontal_flipped(self): self.scatterplot.direction = 'flipped' self.scatterplot.orientation = 'h' self.assertEqual(self.scatterplot.origin, 'bottom right') self.assertEqual(self.scatterplot.x_mapper, self.scatterplot.index_mapper) self.assertIsNone(self.scatterplot.y_mapper) gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_1d_custom(self): path = CompiledPath() path.move_to(-5, -5) path.line_to(5, 5) path.line_to(5, -5) path.line_to(-5, 5) path.line_to(-5, -5) self.scatterplot.marker = 'custom' self.scatterplot.custom_symbol = path gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_slow(self): """ Coverage test to check multiple marker size works """ size = (50, 50) scatterplot = create_scatter_plot( data=[range(10), range(10)], marker="circle", border_visible=False, marker_size=range(1, 11), ) scatterplot.outer_bounds = list(size) gc = PlotGraphicsContext(size) gc.render_component(scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
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 _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 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)
def test_data_label_arrow_not_visible(self): # Regression test for https://github.com/enthought/chaco/issues/281 # Before the problem was fixed, this test (specifically, using # arrow_visible=False in the DataLabel constructor) would raise an # exception because of an undefined reference. size = (50, 50) plot = create_scatter_plot(data=[range(10), range(10)]) label = DataLabel(component=plot, data_point=(4, 4), marker_color="red", marker_size=3, label_position=(20, 50), label_style='bubble', label_text="Something interesting", label_format="at x=%(x).2f, y=%(y).2f", arrow_visible=False) plot.overlays.append(label) plot.outer_bounds = list(size) gc = PlotGraphicsContext(size) gc.render_component(plot)
def test_scatter_custom(self): """ Coverage test to check custom markers work """ # build path path = CompiledPath() path.move_to(-5, -5) path.line_to(5, 5) path.line_to(5, -5) path.line_to(-5, 5) path.line_to(-5, -5) size = (50, 50) scatterplot = create_scatter_plot( data=[range(10), range(10)], marker='custom', border_visible=False, ) scatterplot.custom_symbol = path scatterplot.outer_bounds = list(size) gc = PlotGraphicsContext(size) gc.render_component(scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_custom(self): """ Coverage test to check custom markers work """ # build path path = CompiledPath() path.move_to(-5, -5) path.line_to(5, 5) path.line_to(5, -5) path.line_to(-5, 5) path.line_to(-5, -5) size = (50, 50) scatterplot = create_scatter_plot( data=[list(range(10)), list(range(10))], marker='custom', border_visible=False, ) scatterplot.custom_symbol = path scatterplot.outer_bounds = list(size) gc = PlotGraphicsContext(size) gc.render_component(scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
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 test_errorbarplot(self): """ Coverage test to check basic case works """ size = (50, 50) x = np.array([1, 2]) y = np.array([5, 10]) errors = np.array([1, 2]) low = ArrayDataSource(y - errors) high = ArrayDataSource(y + errors) errorbar_plot = ErrorBarPlot( index=ArrayDataSource(x), values=ArrayDataSource(y), index_mapper=LinearMapper(range=DataRange1D(low=0, high=3)), value_mapper=LinearMapper(range=DataRange1D(low=0, high=15)), value_low=low, value_high=high, color='blue', line_width=3.0, ) errorbar_plot.outer_bounds = list(size) gc = PlotGraphicsContext(size) gc.render_component(errorbar_plot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_1d_rotated(self): self.scatterplot.text_rotate_angle = 45 gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
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 test_scatter_1d_line_style(self): self.scatterplot.line_style = 'dash' gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
class TestColormappedScatterplot(unittest.TestCase): def setUp(self): self.index = ArrayDataSource(arange(10)) self.value = ArrayDataSource(arange(10)) self.color_data = ArrayDataSource(arange(10)) self.size_data = arange(10) self.index_range = DataRange1D() self.index_range.add(self.index) self.index_mapper = LinearMapper(range=self.index_range) self.value_range = DataRange1D() self.value_range.add(self.value) self.value_mapper = LinearMapper(range=self.value_range) self.color_range = DataRange1D() self.color_range.add(self.color_data) self.color_mapper = jet(self.color_range) self.scatterplot = ColormappedScatterPlot( index=self.index, value=self.value, index_mapper=self.index_mapper, value_mapper=self.value_mapper, color_data=self.color_data, marker_size=self.size_data, color_mapper=self.color_mapper, ) self.scatterplot.outer_bounds = [50, 50] self.gc = PlotGraphicsContext((50, 50)) def test_scatter_render(self): """ Coverage test to check basic case works """ self.gc.render_component(self.scatterplot) actual = self.gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255)) def test_scatter_circle(self): """ Coverage test to check circles work """ self.scatterplot.marker = 'circle' self.gc.render_component(self.scatterplot) actual = self.gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255)) @skip def test_scatter_custom(self): """ Coverage test to check custom markers work... XXX ...which apparently they currently don't. See #232. """ # build path path = CompiledPath() path.begin_path() path.move_to(-5, -5) path.line_to(-5, 5) path.line_to(5, 5) path.line_to(5, -5) path.line_to(-5, -5) self.scatterplot.marker = 'custom' self.scatterplot.custom_symbol = path self.gc.render_component(self.scatterplot) actual = self.gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255)) def test_colormap_updated(self): """ If colormapper updated then we need to redraw """ self.color_mapper.updated = True self.assertFalse(self.scatterplot.draw_valid)
def test_scatter_1d_circle(self): self.scatterplot.marker = 'circle' gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
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 test_linescatter_1d_color(self): self.linescatterplot.color = 'orange' gc = PlotGraphicsContext(self.size) gc.render_component(self.linescatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def test_scatter_1d_thicker(self): self.scatterplot.line_width = 2.0 gc = PlotGraphicsContext(self.size) gc.render_component(self.scatterplot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255))
def render_agg(): gc2 = PlotGraphicsContext((800,600), dpi=DPI) gc2.render_component(container) gc2.save("/tmp/kiva_agg.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_renderer_result(renderer, filename): renderer.padding = 0 gc = PlotGraphicsContext(renderer.outer_bounds) with gc: gc.render_component(renderer) gc.save(filename)
from chaco.api import PlotGraphicsContext 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()