def get_colorbar_plot(self, bounds=(0,1)): """ Create a colorbar plot to be added to a plot-container Arguments: bounds -- (min, max) tuple sets the intensity range for the colormap Returns a Chaco2 Plot object containing the colorbar. """ cb_rgba = array_to_rgba( N.repeat(N.linspace(1, 0, num=1024)[:,N.newaxis], 20, axis=1), cmap=self.get_colormap_object()) if self._cbar_orientation is 'h': cb_rgba = cb_rgba.T[::-1] data = ArrayPlotData(colorbar=cb_rgba) # Create the plot object cb = Plot(data, width=self._cbar_width, resizable=self._cbar_orientation, padding_left=0, padding_top=0) cb.img_plot('colorbar', name='colorbar', xbounds=bounds, ybounds=bounds, origin='top left') # Plot tweaks if self._cbar_orientation is 'v': cb.x_axis.visible = False cb.y_axis.orientation = 'right' else: cb.y_axis.visible = False cb.x_axis.orientation = 'bottom' return cb
def render_image(self): plot = Plot(self.img_plotdata, default_origin="top left") img = plot.img_plot("imagedata", colormap=gray)[0] plot.title = "%s of %s: " % (self.img_idx + 1, self.numfiles) + self.titles[self.img_idx] plot.aspect_ratio = float(self.sig.data.shape[1]) / float( self.sig.data.shape[0]) #if not self.ShowCC: csr = CursorTool(img, drag_button='left', color='white', line_width=2.0) self.csr = csr csr.current_position = self.left, self.top img.overlays.append(csr) # attach the rectangle tool plot.tools.append(PanTool(plot, drag_button="right")) zoom = ZoomTool(plot, tool_mode="box", always_on=False, aspect_ratio=plot.aspect_ratio) plot.overlays.append(zoom) self.img_plot = plot return plot
def __init__(self, **traits): super(PointSelectionDemo, self).__init__(**traits) x = np.random.rand(100) y = np.random.rand(100) data = ArrayPlotData(x=x, y=y) plot = Plot(data, padding=25) self.scatter = scatter = plot.plot(("x", "y"), type="scatter", marker_size=4)[0] self.select_tools = {} for i, c in enumerate(Colors.keys()): hover_name = "hover_%s" % c selection_name = "selections_%s" % c self.select_tools[c] = ScatterInspector(scatter, hover_metadata_name=hover_name, selection_metadata_name=selection_name) scatter.overlays.append(ScatterInspectorOverlay(scatter, hover_metadata_name = hover_name, selection_metadata_name=selection_name, hover_color = "transparent", hover_outline_color = c, hover_marker_size = 6, hover_line_width = 1, selection_color = Colors[c], )) scatter.active_tool = self.select_tools[self.color] scatter.index.on_trait_change(self.selection_changed, 'metadata_changed') self.plot = plot self.data = data
def __init__(self, signal_instance): super(TemplatePicker, self).__init__() try: import cv except: print "OpenCV unavailable. Can't do cross correlation without it. Aborting." return None self.OK_custom = OK_custom_handler() self.sig = signal_instance if not hasattr(self.sig.mapped_parameters, "original_files"): self.sig.data = np.atleast_3d(self.sig.data) self.titles = [self.sig.mapped_parameters.name] else: self.numfiles = len( self.sig.mapped_parameters.original_files.keys()) self.titles = self.sig.mapped_parameters.original_files.keys() tmp_plot_data = ArrayPlotData( imagedata=self.sig.data[self.top:self.top + self.tmp_size, self.left:self.left + self.tmp_size, self.img_idx]) tmp_plot = Plot(tmp_plot_data, default_origin="top left") tmp_plot.img_plot("imagedata", colormap=jet) tmp_plot.aspect_ratio = 1.0 self.tmp_plot = tmp_plot self.tmp_plotdata = tmp_plot_data self.img_plotdata = ArrayPlotData( imagedata=self.sig.data[:, :, self.img_idx]) self.img_container = self._image_plot_container() self.crop_sig = None
def _create_plot_component(obj): # Setup the spectrum plot frequencies = linspace(0.0, MAX_FREQ, num=MAX_FREQN) obj.spectrum_data = ArrayPlotData(frequency=frequencies) empty_amplitude = zeros(MAX_FREQN) obj.spectrum_data.set_data("amplitude", empty_amplitude) obj.spectrum_plot = Plot(obj.spectrum_data) obj.spectrum_plot.plot(("frequency", "amplitude"), name="Spectrum", color="red") obj.spectrum_plot.padding = 50 obj.spectrum_plot.title = "Spectrum" spec_range = obj.spectrum_plot.plots.values()[0][0].value_mapper.range spec_range.low = 0.0 spec_range.high = 150.0 # spectrum amplitude maximum obj.spectrum_plot.index_axis.title = "Frequency (hz)" obj.spectrum_plot.value_axis.title = "Amplitude" # Time Series plot times = linspace(0.0, float(TIME_NUM_SAMPLES) / SAMPLING_RATE, num=TIME_NUM_SAMPLES) obj.time_data = ArrayPlotData(time=times) empty_amplitude = zeros(TIME_NUM_SAMPLES) obj.time_data.set_data("amplitude", empty_amplitude) obj.time_data.set_data("amplitude_1", empty_amplitude) obj.time_plot = Plot(obj.time_data) obj.time_plot.plot(("time", "amplitude"), name="Time", color="blue", alpha=0.5) obj.time_plot.plot(("time", "amplitude_1"), name="Time", color="red", alpha=0.5) obj.time_plot.padding = 50 obj.time_plot.title = "Time" obj.time_plot.index_axis.title = "Time (seconds)" obj.time_plot.value_axis.title = "Amplitude" time_range = obj.time_plot.plots.values()[0][0].value_mapper.range time_range.low = -1 time_range.high = 1 # Spectrogram plot spectrogram_data = zeros((MAX_FREQN, SPECTROGRAM_LENGTH)) obj.spectrogram_plotdata = ArrayPlotData() obj.spectrogram_plotdata.set_data("imagedata", spectrogram_data) spectrogram_plot = Plot(obj.spectrogram_plotdata) max_time = float(SPECTROGRAM_LENGTH * NUM_SAMPLES) / SAMPLING_RATE # max_freq = float(SAMPLING_RATE / 2) max_freq = float(MAX_FREQ) spectrogram_plot.img_plot( "imagedata", name="Spectrogram", xbounds=(0, max_time), ybounds=(0, max_freq), colormap=jet ) range_obj = spectrogram_plot.plots["Spectrogram"][0].value_mapper.range range_obj.high = 2 # brightness of specgram range_obj.low = 0.0 range_obj.edit_traits() spectrogram_plot.title = "Spectrogram" obj.spectrogram_plot = spectrogram_plot container = HPlotContainer() container.add(obj.spectrum_plot) container.add(obj.time_plot) container.add(spectrogram_plot) return container
def _create_corr_plot(self): plot = Plot(self.plotdata, padding=0) plot.padding_left = 25 plot.padding_bottom = 25 plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) self.corr_plot = plot
def _create_plot_component(): # Create a random scattering of XY pairs x = random.uniform(0.0, 10.0, 50) y = random.uniform(0.0, 5.0, 50) pd = ArrayPlotData(x = x, y = y) plot = Plot(pd, border_visible=True, overlay_border=True) scatter = plot.plot(("x", "y"), type="scatter", color="lightblue")[0] # Tweak some of the plot properties plot.set(title="Scatter Inspector Demo", padding=50) # Attach some tools to the plot plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) # Attach the inspector and its overlay scatter.tools.append(ScatterInspector(scatter)) overlay = ScatterInspectorOverlay(scatter, hover_color="red", hover_marker_size=6, selection_marker_size=6, selection_color="yellow", selection_outline_color="purple", selection_line_width=3) scatter.overlays.append(overlay) return plot
def __init__(self, filename, dataname1, dataname2, unit): super(doubleplott, self).__init__() with h5py.File(filename, 'r') as f: vdata1 = f['log'][dataname1].value [1:] tdata1 = f['log'][dataname2+'_time'].value [1:] vdata2 = f['log'][dataname2].value [1:] tdata2 = f['log'][dataname2+'_time'].value [1:] startend = measure(tdata1, tdata2) vlist1 = timegrid(startend[0], startend[1], unit, tdata1, vdata1) vlist2 = timegrid(startend[0], startend[1], unit, tdata2, vdata2) #print[vlist1] #print[vlist2] result = mfilter(vlist1,vlist2) plotdata = ArrayPlotData(x = result[0], y = result[1]) plotm = Plot(plotdata) plotm.plot(("x", "y"), type="scatter", color="red") plotm.title = dataname1+'-'+dataname2+'-plot' self.plot = plotm plotm.tools.append(PanTool(plotm)) plotm.tools.append(ZoomTool(plotm)) plotm.tools.append(DragZoom(plotm, drag_button="right"))
def _create_plot_component(): # Create some x-y data series to plot x = linspace(-2.0, 10.0, 40) pd = ArrayPlotData(index = x, y0=jn(0,x)) # Create some line plots of some of the data plot1 = Plot(pd, title="render_style = hold", padding=50, border_visible=True, overlay_border = True) plot1.legend.visible = True lineplot = plot1.plot(("index", "y0"), name="j_0", color="red", render_style="hold") # Attach some tools to the plot attach_tools(plot1) # Create a second scatter plot of one of the datasets, linking its # range to the first plot plot2 = Plot(pd, range2d=plot1.range2d, title="render_style = connectedhold", padding=50, border_visible=True, overlay_border=True) plot2.plot(('index', 'y0'), color="blue", render_style="connectedhold") attach_tools(plot2) # Create a container and add our plots container = HPlotContainer() container.add(plot1) container.add(plot2) return container
def _create_returns_plot(self): plot = Plot(self.plotdata) plot.legend.visible = True #FIXME: The legend move tool doesn't seem to quite work right now #plot.legend.tools.append(LegendTool(plot.legend)) plot.x_axis = None x_axis = PlotAxis(plot, orientation="bottom", tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem())) plot.overlays.append(x_axis) plot.x_grid.tick_generator = x_axis.tick_generator for i, name in enumerate(self.plotdata.list_data()): if name == "times": continue renderer = plot.plot(("times", name), type="line", name=name, color=tuple(COLOR_PALETTE[i]))[0] # Tricky: need to set auto_handle_event on the RangeSelection # so that it passes left-clicks to the PanTool # FIXME: The range selection is still getting the initial left down renderer.tools.append(RangeSelection(renderer, left_button_selects = False, auto_handle_event = False)) plot.tools.append(PanTool(plot, drag_button="left", constrain=True, constrain_direction="x")) plot.overlays.append(ZoomTool(plot, tool_mode="range", max_zoom_out=1.0)) # Attach the range selection to the last renderer; any one will do self._range_selection_overlay = RangeSelectionOverlay(renderer, metadata_name="selections") renderer.overlays.append(self._range_selection_overlay) # Grab a reference to the Time axis datasource and add a listener to its # selections metadata self.times_ds = renderer.index self.times_ds.on_trait_change(self._selections_changed, 'metadata_changed') self.returns_plot = plot
def _create_plot_component():# Create a scalar field to colormap xbounds = (-2*pi, 2*pi, 600) ybounds = (-1.5*pi, 1.5*pi, 300) xs = linspace(*xbounds) ys = linspace(*ybounds) x, y = meshgrid(xs,ys) z = sin(x)*y # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds = xbounds[:2], ybounds = ybounds[:2], colormap=jet)[0] # Tweak some of the plot properties plot.title = "My First Image Plot" plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool, bgcolor="white", border_visible=True) img_plot.overlays.append(overlay) return plot
def _main_tab_default(self): self.sal_plot = Plot(self.plot_data) self.sal_plot.plot(('time_ds', 'sal_ds'), type='line') #sal_plot.overlays.append(PlotAxis(sal_plot, orientation='left')) #bottom_axis = PlotAxis(sal_plot, orientation="bottom",# mapper=xmapper, # tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem())) #sal_plot.overlays.append(bottom_axis) #hgrid, vgrid = add_default_grids(sal_plot) #vgrid.tick_generator = bottom_axis.tick_generator #sal_plot.tools.append(PanTool(sal_plot, constrain=True, # constrain_direction="x")) #sal_plot.overlays.append(ZoomTool(sal_plot, drag_button="right", # always_on=True, # tool_mode="range", # axis="index", # max_zoom_out_factor=10.0, # )) container = VPlotContainer(bgcolor="lightblue", spacing=40, padding=50, fill_padding=False) container.add(sal_plot) #container.add(price_plot) #container.overlays.append(PlotLabel("Salinity Plot with Date Axis", # component=container, # #font="Times New Roman 24")) # font="Arial 24")) return container
def _create_plot_component():# Create a scalar field to colormap xbounds = (-2*pi, 2*pi, 600) ybounds = (-1.5*pi, 1.5*pi, 300) xs = linspace(*xbounds) ys = linspace(*ybounds) x, y = meshgrid(xs,ys) z = sin(x)*y # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds=xbounds[:2], ybounds=ybounds[:2], colormap=jet)[0] # Tweak some of the plot properties plot.title = "Image Plot with Lasso" plot.padding = 50 lasso_selection = LassoSelection(component=img_plot) lasso_selection.on_trait_change(lasso_updated, "disjoint_selections") lasso_overlay = LassoOverlay(lasso_selection = lasso_selection, component=img_plot) img_plot.tools.append(lasso_selection) img_plot.overlays.append(lasso_overlay) return plot
def __init__(self): self.data = ArrayPlotData() self.set_empty_data() self.plot = Plot(self.data, padding=10) scatter = self.plot.plot(("x","y", "c"), type="cmap_scatter", marker_size=1, color_mapper=make_color_map(), line_width=0)[0] self.plot.x_grid.visible = False self.plot.y_grid.visible = False self.plot.x_axis.visible = False self.plot.y_axis.visible = False self.tool = TrianglesTool(self.plot) self.plot.overlays.append(self.tool) try: with file("ifs_chaco.data","rb") as f: tmp = pickle.load(f) self.ifs_names = [x[0] for x in tmp] self.ifs_points = [np.array(x[1]) for x in tmp] if len(self.ifs_names) > 0: self.current_name = self.ifs_names[-1] except: pass self.tool.on_trait_change(self.triangle_changed, 'changed') self.timer = Timer(10, self.ifs_calculate)
def makeplot2( x,y,title): plotdata = ArrayPlotData(x=x, y=y ) #, y2=y2, y3=y3 ) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.title = title return plot
class MyPlot(HasTraits): """ Displays a plot with a few buttons to control which overlay to display """ plot = Instance(Plot) traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False), resizable=True) def __init__(self, x_index, y_index, data, **kw): super(MyPlot, self).__init__(**kw) # Create the data source for the MultiLinePlot. ds = MultiArrayDataSource(data=data) xs = ArrayDataSource(x_index, sort_order='ascending') xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(y_index, sort_order='ascending') yrange = DataRange1D() yrange.add(ys) mlp = MultiLinePlot( index = xs, yindex = ys, index_mapper = LinearMapper(range=xrange), value_mapper = LinearMapper(range=yrange), value=ds, global_max = data.max(), global_min = data.min(), **kw) self.plot = Plot() self.plot.add(mlp)
def _plot_update(self): num_display_points = 100 * 25 # For 1000 Hz if self.model.master_index > num_display_points: disp_begin = self.model.master_index - num_display_points disp_end = self.model.master_index print 'disp_begin', disp_begin print 'disp_end', disp_end ydata = self.clean_time_series( np.array(self.model._ydata[disp_begin:disp_end])) xdata = np.array(self.model._tdata[disp_begin:disp_end]) self.plot_data.set_data("y", ydata) self.plot_data.set_data("x", xdata) else: self.plot_data.set_data( "y", self.clean_time_series( self.model._ydata[0:self.model.master_index])) self.plot_data.set_data( "x", self.model._tdata[0:self.model.master_index]) self.plot = Plot(self.plot_data) # self.plot.delplot('old') the_plot = self.plot.plot(("x", "y"), type="line", name='old', color="green")[0] self.plot.request_redraw()
def _create_plot_component(): pd = ArrayPlotData(x=random(100), y=random(100)) # Create some line plots of some of the data plot = Plot(pd) # Create a scatter plot and get a reference to it (separate from the # Plot object) because we'll need it for the regression tool below. scatterplot = plot.plot(("x", "y"), color="blue", type="scatter")[0] # Tweak some of the plot properties plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, drag_button="right")) plot.overlays.append(ZoomTool(plot)) # Add the regression tool and overlay. These need to be added # directly to the scatterplot instance (and not the Plot instance). regression = RegressionLasso(scatterplot, selection_datasource=scatterplot.index) scatterplot.tools.append(regression) scatterplot.overlays.append(RegressionOverlay(scatterplot, lasso_selection=regression)) return plot
def _create_plot_component(): # Create some RGBA image data image = zeros((200,400,4), dtype=uint8) image[:,0:40,0] += 255 # Vertical red stripe image[0:25,:,1] += 255 # Horizontal green stripe; also yellow square image[-80:,-160:,2] += 255 # Blue square image[:,:,3] = 255 # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", image) # Create the plot plot = Plot(pd, default_origin="top left") plot.x_axis.orientation = "top" img_plot = plot.img_plot("imagedata")[0] # Tweak some of the plot properties plot.bgcolor = "white" # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) plot.overlays.append(ZoomTool(component=plot, tool_mode="box", always_on=False)) imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) plot.overlays.append(ImageInspectorOverlay(component=img_plot, image_inspector=imgtool)) return plot
def __init__(self, link): super(SolutionView, self).__init__() self.link = link self.link.add_callback(MSG_SOLUTION, self.solution_callback) self.link.add_callback(MSG_SOLUTION_DOPS, self.dops_callback) self.link.add_callback(MSG_SOLUTION_PRS, self.prs_callback) self.link.add_callback(MSG_SOLUTION_PRED_PRS, self.pred_prs_callback) self.plot_data = ArrayPlotData(n=[0.0], e=[0.0], h=[0.0], t=[0.0], ref_n=[0.0], ref_e=[0.0]) self.plot = Plot(self.plot_data) #, auto_colors=colours_list) self.plot.plot(('n', 'e'), type='scatter', color='blue', marker='plus') self.plot.plot(('ref_n', 'ref_e'), type='scatter', color='red', marker='cross', marker_size=10, line_width=1.5 ) #self.plot.plot(('h', 'e'), type='line', color='red') self.pr_plot_data = ArrayPlotData(t=[0.0]) self.pr_plot = Plot(self.pr_plot_data, auto_colors=colours_list) self.pr_plot.value_range.tight_bounds = False #self.pr_plot.value_range.low_setting = 0.0 for n in range(TRACK_N_CHANNELS): self.pr_plot_data.set_data('prs'+str(n), [0.0]) self.pr_plot.plot(('t', 'prs'+str(n)), type='line', color='auto') #self.pr_plot_data.set_data('pred_prs'+str(n), [0.0]) #self.pr_plot.plot(('t', 'pred_prs'+str(n)), type='line', color='auto') self.python_console_cmds = { 'solution': self }
def _image_plot_default(self): plot = Plot(self.image_data, default_origin="top left") #plot.x_axis.orientation = "top" img_plot = plot.img_plot("image_data")[0] plot.bgcolor = "black" return plot
def _create_plot_component(): # Create a scalar field to colormap xs = linspace(0, 10, 600) ys = linspace(0, 5, 600) x, y = meshgrid(xs, ys) z = exp(-(x**2 + y**2) / 100) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds=(0, 10), ybounds=(0, 5), colormap=jet)[0] # Tweak some of the plot properties plot.title = "My First Image Plot" plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False) img_plot.overlays.append(zoom) return plot
def __init__(self): x, y = np.ogrid[-2*np.pi:2*np.pi:256j, -2*np.pi:2*np.pi:256j] self.img_data = np.sin(x)*y #self.img_mask = np.zeros((len(x), len(y[0]), 4), dtype=np.uint8) #self.img_mask[:, :, 3] = 255 self.img_index = np.array(list((np.broadcast(y, x)))) plotdata = ArrayPlotData(img_data=self.img_data, mask_data=self.img_data) plot1 = Plot(plotdata, padding=10) img_plot = plot1.img_plot("img_data", xbounds=(np.min(x), np.max(x)), ybounds=(np.min(y), np.max(y)))[0] self.lasso = LassoSelection(img_plot) img_plot.tools.append(self.lasso) self.ll = LassoOverlay(img_plot, lasso_selection=self.lasso) img_plot.overlays.append(self.ll) self.lasso.on_trait_change(self._selection_changed, 'selection_completed') plot2 = Plot(plotdata, padding=10) plot2.img_plot("mask_data") self.plot = HPlotContainer(plot1, plot2) self.plot1 = plot1 self.plot2 = plot2 self.plotdata = plotdata
def _do_plot_boilerplate(kwargs, image=False): """ Used by various plotting functions. Checks/handles hold state, returns a Plot object for the plotting function to use. """ if kwargs.has_key("hold"): hold(kwargs["hold"]) del kwargs["hold"] # Check for an active window; if none, open one. if len(session.windows) == 0: if image: win = session.new_window(is_image=True) activate(win) else: figure() cont = session.active_window.get_container() if not cont: cont = Plot(session.data) session.active_window.set_container(cont) existing_tools = [type(t) for t in (cont.tools + cont.overlays)] if not PanTool in existing_tools: cont.tools.append(PanTool(cont)) if not ZoomTool in existing_tools: cont.overlays.append(ZoomTool(cont, tool_mode="box", always_on=True, drag_button="right")) if not session.hold: cont.delplot(*cont.plots.keys()) return cont
def __init__(self, signal_instance): super(TemplatePicker, self).__init__() try: import cv except: print "OpenCV unavailable. Can't do cross correlation without it. Aborting." return None self.OK_custom=OK_custom_handler() self.sig=signal_instance if not hasattr(self.sig.mapped_parameters,"original_files"): self.sig.data=np.atleast_3d(self.sig.data) self.titles=[self.sig.mapped_parameters.name] else: self.numfiles=len(self.sig.mapped_parameters.original_files.keys()) self.titles=self.sig.mapped_parameters.original_files.keys() tmp_plot_data=ArrayPlotData(imagedata=self.sig.data[self.top:self.top+self.tmp_size,self.left:self.left+self.tmp_size,self.img_idx]) tmp_plot=Plot(tmp_plot_data,default_origin="top left") tmp_plot.img_plot("imagedata", colormap=jet) tmp_plot.aspect_ratio=1.0 self.tmp_plot=tmp_plot self.tmp_plotdata=tmp_plot_data self.img_plotdata=ArrayPlotData(imagedata=self.sig.data[:,:,self.img_idx]) self.img_container=self._image_plot_container() self.crop_sig=None
def _create_plot_component(self): pd = self.pd # Create the plot plot = Plot(pd, default_origin="top left",orientation="h") shape = pd.get_data('imagedata').shape plot.aspect_ratio = float(shape[1]) / shape[0] plot.x_axis.orientation = "top" #plot.y_axis.orientation = "top" #img_plot = plot.img_plot("imagedata",colormap = jet)[0] img_plot = plot.img_plot("imagedata",name = 'image', colormap = jet)[0] # Tweak some of the plot properties #plot.bgcolor = "white" plot.bgcolor = bg_color # Attach some tools to the plot plot.tools.append(PanTool(plot,constrain_key="shift", drag_button = 'right')) printer = DataPrinter(component=plot, process = self.process_selection) plot.tools.append(printer) plot.overlays.append(ZoomTool(component=plot, tool_mode="box", always_on=False)) #plot.title = 'Default image' imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) plot.overlays.append(ImageInspectorOverlay(component=img_plot, image_inspector=imgtool)) return plot
def __init__(self, **traits): super(HistDemo, self).__init__(**traits) img = cv.imread("lena.jpg") gray_img = cv.Mat() cv.cvtColor(img, gray_img, cv.CV_BGR2GRAY) self.img = gray_img self.img2 = self.img.clone() result = cv.MatND() r = cv.vector_float32([0, 256]) ranges = cv.vector_vector_float32([r, r]) cv.calcHist(cv.vector_Mat([self.img]), channels=cv.vector_int([0, 1]), mask=cv.Mat(), hist=result, histSize=cv.vector_int([256]), ranges=ranges) data = ArrayPlotData(x=np.arange(0, len(result[:])), y=result[:]) self.plot = Plot(data, padding=10) line = self.plot.plot(("x", "y"))[0] self.select_tool = RangeSelection(line, left_button_selects=True) line.tools.append(self.select_tool) self.select_tool.on_trait_change(self._selection_changed, "selection") line.overlays.append(RangeSelectionOverlay(component=line)) cv.imshow("Hist Demo", self.img) self.timer = Timer(50, self.on_timer)
def _create_plot_component(obj): # Setup the spectrum plot frequencies = linspace(0.0, float(SAMPLING_RATE)/2, num=NUM_SAMPLES/2) obj.spectrum_data = ArrayPlotData(frequency=frequencies) empty_amplitude = zeros(NUM_SAMPLES/2) obj.spectrum_data.set_data('amplitude', empty_amplitude) obj.spectrum_plot = Plot(obj.spectrum_data) obj.spectrum_plot.plot(("frequency", "amplitude"), name="Spectrum", color="red") obj.spectrum_plot.padding = 50 obj.spectrum_plot.title = "Spectrum" spec_range = obj.spectrum_plot.plots.values()[0][0].value_mapper.range spec_range.low = 0.0 spec_range.high = 5.0 obj.spectrum_plot.index_axis.title = 'Frequency (hz)' obj.spectrum_plot.value_axis.title = 'Amplitude' # Time Series plot times = linspace(0.0, float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES) obj.time_data = ArrayPlotData(time=times) empty_amplitude = zeros(NUM_SAMPLES) obj.time_data.set_data('amplitude', empty_amplitude) obj.time_plot = Plot(obj.time_data) obj.time_plot.plot(("time", "amplitude"), name="Time", color="blue") obj.time_plot.padding = 50 obj.time_plot.title = "Time" obj.time_plot.index_axis.title = 'Time (seconds)' obj.time_plot.value_axis.title = 'Amplitude' time_range = obj.time_plot.plots.values()[0][0].value_mapper.range time_range.low = -0.2 time_range.high = 0.2 # Spectrogram plot spectrogram_data = zeros(( NUM_SAMPLES/2, SPECTROGRAM_LENGTH)) obj.spectrogram_plotdata = ArrayPlotData() obj.spectrogram_plotdata.set_data('imagedata', spectrogram_data) spectrogram_plot = Plot(obj.spectrogram_plotdata) max_time = float(SPECTROGRAM_LENGTH * NUM_SAMPLES) / SAMPLING_RATE max_freq = float(SAMPLING_RATE / 2) spectrogram_plot.img_plot('imagedata', name='Spectrogram', xbounds=(0, max_time), ybounds=(0, max_freq), colormap=jet, ) range_obj = spectrogram_plot.plots['Spectrogram'][0].value_mapper.range range_obj.high = 5 range_obj.low = 0.0 spectrogram_plot.title = 'Spectrogram' obj.spectrogram_plot = spectrogram_plot container = HPlotContainer() container.add(obj.spectrum_plot) container.add(obj.time_plot) container.add(spectrogram_plot) return container
def _create_plot_component(obj): # Setup the spectrum plot frequencies = linspace(0.0, float(SAMPLING_RATE)/2, num=NUM_SAMPLES/2) obj.spectrum_data = ArrayPlotData(frequency=frequencies) empty_amplitude = zeros(NUM_SAMPLES/2) obj.spectrum_data.set_data('amplitude', empty_amplitude) obj.spectrum_plot = Plot(obj.spectrum_data) spec_renderer = obj.spectrum_plot.plot(("frequency", "amplitude"), name="Spectrum", color="red")[0] obj.spectrum_plot.padding = 50 obj.spectrum_plot.title = "Spectrum" spec_range = obj.spectrum_plot.plots.values()[0][0].value_mapper.range spec_range.low = 0.0 spec_range.high = 5.0 obj.spectrum_plot.index_axis.title = 'Frequency (hz)' obj.spectrum_plot.value_axis.title = 'Amplitude' # Time Series plot times = linspace(0.0, float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES) obj.time_data = ArrayPlotData(time=times) empty_amplitude = zeros(NUM_SAMPLES) obj.time_data.set_data('amplitude', empty_amplitude) obj.time_plot = Plot(obj.time_data) obj.time_plot.plot(("time", "amplitude"), name="Time", color="blue") obj.time_plot.padding = 50 obj.time_plot.title = "Time" obj.time_plot.index_axis.title = 'Time (seconds)' obj.time_plot.value_axis.title = 'Amplitude' time_range = obj.time_plot.plots.values()[0][0].value_mapper.range time_range.low = -0.2 time_range.high = 0.2 # Spectrogram plot values = [zeros(NUM_SAMPLES/2) for i in xrange(SPECTROGRAM_LENGTH)] p = WaterfallRenderer(index = spec_renderer.index, values = values, index_mapper = LinearMapper(range = obj.spectrum_plot.index_mapper.range), value_mapper = LinearMapper(range = DataRange1D(low=0, high=SPECTROGRAM_LENGTH)), y2_mapper = LinearMapper(low_pos=0, high_pos=8, range=DataRange1D(low=0, high=15)), ) spectrogram_plot = p obj.spectrogram_plot = p dummy = Plot() dummy.padding = 50 dummy.index_axis.mapper.range = p.index_mapper.range dummy.index_axis.title = "Frequency (hz)" dummy.add(p) container = HPlotContainer() container.add(obj.spectrum_plot) container.add(obj.time_plot) c2 = VPlotContainer() c2.add(dummy) c2.add(container) return c2
def _create_plot_component(): # Create some data numpts = 1000 x = sort(random(numpts)) y = random(numpts) color = exp(-(x**2 + y**2)) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) pd.set_data("color", color) # Create the plot plot = Plot(pd) plot.plot(("index", "value", "color"), type="cmap_scatter", name="my_plot", color_mapper=jet, marker = "square", fill_alpha = 0.5, marker_size = 6, outline_color = "black", border_visible = True, bgcolor = "white") # Tweak some of the plot properties plot.title = "Colormapped Scatter Plot" plot.padding = 50 plot.x_grid.visible = False plot.y_grid.visible = False plot.x_axis.font = "modern 16" plot.y_axis.font = "modern 16" # Right now, some of the tools are a little invasive, and we need the # actual ColomappedScatterPlot object to give to them cmap_renderer = plot.plots["my_plot"][0] # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) selection = ColormappedSelectionOverlay(cmap_renderer, fade_alpha=0.35, selection_type="mask") cmap_renderer.overlays.append(selection) # Create the colorbar, handing in the appropriate range and colormap colorbar = create_colorbar(plot.color_mapper) colorbar.plot = cmap_renderer colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(use_backbuffer = True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" return container
def __init__(self, **traits): super(AnimationPlot, self).__init__(**traits) data = ArrayPlotData(x=[0], y=[0]) plot = Plot(data) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x)" self.plot = plot self.data = data
def load_data(self,X,Y) : self.X = X self.Y = Y plotdata = ArrayPlotData(x = X, y = Y) plot = Plot(plotdata) self.renderer_line = plot.plot(('x','y'),type = 'line', color = "blue")[0] self.renderer_scat = plot.plot(('x','y'),type = 'scatter', color = "blue")[0] self.plot = plot
def __init__(self, x, y, color = "blue"): super(ScatterPlot, self).__init__() plotdata = ArrayPlotData(x = x, y = y) plot = Plot(plotdata) self.renderer = plot.plot(("x", "y"), type = "scatter", color = color)[0] self.plot = plot self.color = color self.configure_traits()
def _create_plot(self, data, name, type="line"): p = Plot(self.plot_data) p.plot(data, name=name, title=name, type=type) p.tools.append(PanTool(p)) zoom = ZoomTool(component=p, tool_mode="box", always_on=False) p.overlays.append(zoom) p.title = name return p
def _vr_image_plot_default(self): plot = Plot(self.vr_image_data, default_origin="top left", size=(512,512)) plot.aspect_ratio = 1.0 #plot.x_axis.orientation = "top" img_plot = plot.img_plot("vr_image_data")[0] plot.bgcolor = "black" return plot
def __init__(self, *args, **kw): HasTraits.__init__(self, *args, **kw) numpoints = 200 plotdata = ArrayPlotData(x=sort(random(numpoints)), y=random(numpoints)) plot = Plot(plotdata) plot.plot(("x", "y"), type="scatter") plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) self.plot = plot
def __init__(self): super(LinePlot, self).__init__() x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x) * x^3" self.plot = plot
def __init__(self): super(ScatterPlotTraits, self).__init__() x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) self.renderer = plot.plot(("x", "y"), type="scatter", color="blue")[0] self.plot = plot
def __init__(self, **traits): super(MandelbrotDemo, self).__init__(**traits) self.data = ArrayPlotData(image=np.zeros((1, 1))) self.plot = Plot(self.data, padding=0) imgplot = self.plot.img_plot("image", colormap=reverse(Blues), interpolation="bilinear")[0] imgplot.tools.append( MandelbrotController(imgplot, application=self) ) self.imgplot = imgplot self.plot.x_axis.visible = False self.plot.y_axis.visible = False
def __init__( self, **traits ): super( ParamController, self ).__init__( **traits ) p = self.rate_plot ( "rates" ) container = Plot() container.add( p ) self.plot = container
def __init__(self): super(ScatterPlotTraits, self).__init__() x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x = x, y = y) plot = Plot(plotdata) self.renderer = plot.plot(("x", "y"), type="scatter", color="blue")[0] self.plot = plot
def __init__(self, x, y, color = "blue", line_width = 4): super(LinePlot, self).__init__() plotdata = ArrayPlotData(x = x, y = y) plot = Plot(plotdata) self.renderer = plot.plot(("x", "y"), type = "line", color = color, line_width = line_width)[0] self.plot = plot self.color = color self.line_width = line_width self.configure_traits()
def __init__(self): super(ImagePlot, self).__init__() x = np.linspace(0, 10, 50) y = np.linspace(0, 5, 50) xgrid, ygrid = np.meshgrid(x, y) z = np.exp(-(xgrid * xgrid + ygrid * ygrid) / 100) plotdata = ArrayPlotData(imagedata=z) plot = Plot(plotdata) plot.img_plot("imagedata", xbounds=x, ybounds=y, colormap=jet) self.plot = plot
def __init__(self, **traits): super(ScatterPlotTraits, self).__init__(**traits) x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 data = ArrayPlotData(x=x, y=y) plot = Plot(data) self.line = plot.plot(("x", "y"), type="scatter", color="blue")[0] self.plot = plot self.data = data
def __init__(self): x = numpy.linspace(-14, 14, 100) y = numpy.sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x) * x^3" self.plot=plot
def __init__(self, **traits): super(LinePlot, self).__init__(**traits) x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 data = ArrayPlotData(x=x, y=y) plot = Plot(data) plot.plot(("x", "y"), type="line", color="blue") plot.title = "sin(x) * x^3" self.plot = plot self.data = data
def __init__(self): # Create the data and the PlotData object x = linspace(-14, 14, 500) y = sin(x) * x**3 plotdata = ArrayPlotData(x = x, y = y) # Create a Plot and associate it with the PlotData plot = Plot(plotdata) # Create a line plot in the Plot plot.plot(("x", "y"), type="line", color="blue") self.plot = plot
def __init__(self, **traits): super(LassoDemoPlot, self).__init__(**traits) x = np.random.random(N) y = np.random.random(N) x2 = np.array([]) y2 = np.array([]) data = ArrayPlotData(x=x, y=y, x2=x2, y2=y2) plot1 = Plot(data, padding=10) scatter_plot1 = plot1.plot(("x", "y"), type="scatter", marker="circle", color="blue")[0] self.lasso = LassoSelection(scatter_plot1, incremental_select=True, selection_datasource=scatter_plot1.index) self.lasso.on_trait_change(self._selection_changed, 'selection_changed') scatter_plot1.tools.append(self.lasso) scatter_plot1.overlays.append( LassoOverlay(scatter_plot1, lasso_selection=self.lasso)) plot2 = Plot(data, padding=10) plot2.index_range = plot1.index_range plot2.value_range = plot1.value_range plot2.plot(("x2", "y2"), type="scatter", marker="circle", color="red") self.plot = HPlotContainer(plot1, plot2) self.plot2 = plot2 self.data = data
def __init__(self, dims=(128, 10)): super(ImagePlot, self).__init__() z = numpy.zeros(dims) self.plotdata = ArrayPlotData(imagedata=z) plot = Plot(self.plotdata) plot.img_plot("imagedata", xbounds=(0, dims[1]), ybounds=(0, dims[0]), colormap=self._cmap) self.plot = plot self.flag = True
class BaseViewer(HasTraits): main_tab = Instance(Component) traits_view = View(Item('main_tab', editor=ComponentEditor), width=500, height=500, resizable=True, title="Salinity Plot") def __init__(self, **kwargs): HasTraits.__init__(self, **kwargs) self.init_data() def init_data(self): file_name = '/home/dpothina/work/apps/pysonde/tests/ysi_test_files/BAYT_20070323_CDT_YS1772AA_000.dat' sonde = Sonde(file_name) sal_ds = np.array([1, 2, 3, 4, 5, 6, 7, 8]) # sonde.data['seawater_salinity'] time_ds = sal_ds**2 # [time.mktime(date.utctimetuple()) for date in sonde.dates] #time_ds = ArrayDataSource(dt) #sal_ds = ArrayDataSource(salinity, sort_order="none") self.plot_data = ArrayPlotData(sal_ds=sal_ds, time_ds=time_ds) def _main_tab_default(self): self.sal_plot = Plot(self.plot_data) self.sal_plot.plot(('time_ds', 'sal_ds'), type='line') #sal_plot.overlays.append(PlotAxis(sal_plot, orientation='left')) #bottom_axis = PlotAxis(sal_plot, orientation="bottom",# mapper=xmapper, # tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem())) #sal_plot.overlays.append(bottom_axis) #hgrid, vgrid = add_default_grids(sal_plot) #vgrid.tick_generator = bottom_axis.tick_generator #sal_plot.tools.append(PanTool(sal_plot, constrain=True, # constrain_direction="x")) #sal_plot.overlays.append(ZoomTool(sal_plot, drag_button="right", # always_on=True, # tool_mode="range", # axis="index", # max_zoom_out_factor=10.0, # )) container = VPlotContainer(bgcolor="lightblue", spacing=40, padding=50, fill_padding=False) container.add(sal_plot) #container.add(price_plot) #container.overlays.append(PlotLabel("Salinity Plot with Date Axis", # component=container, # #font="Times New Roman 24")) # font="Arial 24")) return container
def __init__(self, options, **kwtraits): super(FiberView, self).__init__(**kwtraits) self.model = FiberModel(options) # debugging self.debug = options.debug self.model.debug = options.debug # timing parameters self.max_packets = options.max_packets self.hertz = options.hertz # extend options to model self.model.max_packets = options.max_packets self.model.preallocate_arrays() self.model.num_analog_channels = options.num_analog_channels # generate traits plot self.plot_data = ArrayPlotData(x=self.model._tdata, y=self.model._ydata) self.plot = Plot(self.plot_data) renderer = self.plot.plot(("x", "y"), type="line", name='old', color="green")[0] # self.plot.delplot('old') # recording flags self.model.recording = False self.model.trialEnded = True print 'Viewer initialized.' # should we wait for a ttl input to start? if options.ttl_start: self.model.ttl_start = True self.ttl_received = False # initialize FIO0 for TTL input self.FIO0_DIR_REGISTER = 6100 self.FIO0_STATE_REGISTER = 6000 self.model.labjack.writeRegister(self.FIO0_DIR_REGISTER, 0) # Set FIO0 low # initialize output array self.out_arr = None # keep track of number of runs self.run_number = 0 self.timer = Timer(self.model.dt, self.time_update) # update every 1 ms
def _plot_xy8_default(self): plot = Plot(self.plot_xy8_data, padding_left=60, padding_top=25, padding_right=10, padding_bottom=50) plot.plot(('xy8_plot_x', 'xy8_plot_y'), style='line', color='blue') plot.index_axis.title = 'tau [micro-s]' plot.value_axis.title = 'Intensity [a.u.]' plot.title = 'xy8 raw data' plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) return plot
def __init__(self, dims=(128, 10)): super(ImagePlot, self).__init__() #z = numpy.zeros(dims) self.plotdata = ArrayPlotData(neurons=[0], times=[0]) plot = Plot(self.plotdata) plot.plot( ("times", "neurons"), type="scatter", marker="dot", marker_size=1, color='black', ) self.plot = plot
def __init__(self): super(Probe, self).__init__() x = linspace(0, self.N, self.N / self.d) y = linspace(0, self.N, self.N / self.d) xgrid, ygrid = meshgrid(x[1:], y[1:]) z = exp(-(xgrid * xgrid + ygrid * ygrid) / 10000) plotdata = ArrayPlotData(imagedata=z) plot = Plot(plotdata) self.renderer = plot.img_plot("imagedata", xbounds=x, ybounds=y, colormap=bone) #self.renderer = plot.plot(("x", "y"), type="scatter", color="blue")[0] self.plot = plot
def __init__(self): x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 y2 = np.cos(x) * x**3 plotdata = ArrayPlotData(x=x, y=y, y2=y2) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue", name="sin") plot.plot(("x", "y2"), type="line", color="red", name="cos") #line.index.sort_order = "ascending" plot.title = "sin(x) * x^3" plot.legend.visible = True plot.legend.tools.append(LegendHighlighter(plot.legend)) self.plot = plot self.plotdata = plotdata
def __init__(self): # Create plot data. row = linspace(0, 1, 100) self.data = ones([10, 100]) * row plotdata = ArrayPlotData(imagedata=self.data) # Create a Plot and associate it with the PlotData plot = Plot(plotdata) # Create a line plot in the Plot plot.img_plot("imagedata", xbounds=(0, 1), colormap=color_map_name_dict[self.colormap])[0] plot.y_axis.visible = False self.plot = plot self.plot.aspect_ratio = 5