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 __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 _create_plot_component(): # Create a GridContainer to hold all of our plots container = GridContainer(padding=20, fill_padding=True, bgcolor="lightgray", use_backbuffer=True, shape=(3,3), spacing=(12,12)) # Create the initial series of data x = linspace(-5, 15.0, 100) pd = ArrayPlotData(index = x) # Plot some bessel functions and add the plots to our container for i in range(9): pd.set_data("y" + str(i), jn(i,x)) plot = Plot(pd) plot.plot(("index", "y" + str(i)), color=tuple(COLOR_PALETTE[i]), line_width=2.0, bgcolor = "white", border_visible=True) # Tweak some of the plot properties plot.border_width = 1 plot.padding = 10 # Set each plot's aspect ratio based on its position in the # 3x3 grid of plots. n,m = divmod(i, 3) plot.aspect_ratio = float(n+1) / (m+1) # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Add to the grid container container.add(plot) return container
def _create_plot_component(): # Create some x-y data series (with NaNs) to plot x = linspace(-5.0, 15.0, 500) x[75:125] = nan x[200:250] = nan x[300:330] = nan pd = ArrayPlotData(index = x) pd.set_data("value1", jn(0, x)) pd.set_data("value2", jn(1, x)) # Create some line and scatter plots of the data plot = Plot(pd) plot.plot(("index", "value1"), name="j_0(x)", color="red", width=2.0) plot.plot(("index", "value2"), type="scatter", marker_size=1, name="j_1(x)", color="green") # Tweak some of the plot properties plot.title = "Plots with NaNs" plot.padding = 50 plot.legend.visible = True # 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) return plot
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 __init__(self, **traits): super(ContainerExample, self).__init__(**traits) x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 / 1000 data = ArrayPlotData(x=x, y=y) p1 = Plot(data, padding=30) p1.plot(("x", "y"), type="scatter", color="blue") p1.plot(("x", "y"), type="line", color="blue") p2 = Plot(data, padding=30) p2.plot(("x", "y"), type="line", color="blue") p2.set(bounds=[200, 100], position=[70, 150], bgcolor=(0.9, 0.9, 0.9), unified_draw=True, resizable="") p3 = Plot(data, padding=30) p3.plot(("x", "y"), type="line", color="blue", line_width=2.0) p4 = Plot(data, padding=30) p4.plot(("x", "y"), type="scatter", color="red", marker="circle") c1 = OverlayPlotContainer(p1, p2) c1.fixed_preferred_size = p3.get_preferred_size() c2 = HPlotContainer(c1, p3) c3 = VPlotContainer(p4, c2) self.plot = c3
def _create_plot_component(): # Create some x-y data series to plot x = linspace(-2.0, 10.0, 100) pd = ArrayPlotData(index = x) for i in range(5): pd.set_data("y" + str(i), jn(i,x)) # Create some line plots of some of the data plot1 = Plot(pd, padding=50) plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot1.plot(("index", "y3"), name="j_3", color="blue") # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) plot1.overlays.append(zoom) # Add the scrollbar hscrollbar = PlotScrollBar(component=plot1, axis="index", resizable="h", height=15) plot1.padding_top = 0 hscrollbar.force_data_update() # Create a container and add our plots container = VPlotContainer() container.add(plot1) container.add(hscrollbar) return container
def _stage_map_default(self): # RGBA maps rep_map = array_to_rgba(self.PMap.stage_repr_map, cmap=cm.hot) cov_map = array_to_rgba(self.PMap.stage_coverage_map, cmap=cm.gray) # Data sources and plot object data = ArrayPlotData(fields_x=self.fdata['x'], fields_y=self.fdata['y'], fields_z=self.fdata['peak'], rep=rep_map, cov=cov_map) p = Plot(data) # Plot the field centers p.plot(('fields_x', 'fields_y', 'fields_z'), name='centers', type='cmap_scatter', marker='dot', marker_size=5, color_mapper=copper, line_width=1, fill_alpha=0.6) # Plot the representation and coverage maps p.img_plot('rep', name='rep', xbounds=(0, self.PMap.W), ybounds=(0, self.PMap.H), origin='top left') p.img_plot('cov', name='cov', xbounds=(0, self.PMap.W), ybounds=(0, self.PMap.H), origin='top left') # Start with only the representation map visible p.plots['cov'][0].visible = False p.plots['centers'][0].visible = False # Plot tweaks p.aspect_ratio = 1.0 p.y_axis.title = 'Y (cm)' p.x_axis.title = 'X (cm)' p.x_axis.orientation = 'bottom' p.title = 'Stage Maps' return p
def __init__(self): # Create the data and the PlotData object x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x = x, y = y) # Create the scatter plot scatter = Plot(plotdata) scatter.plot(("x", "y"), type="scatter", color="blue") # Create the line plot line = Plot(plotdata) line.plot(("x", "y"), type="line", color="blue") # Create a horizontal container and put the two plots inside it self.container = HPlotContainer(scatter, line) # Add pan/zoom so we can see they are connected scatter.tools.append(PanTool(scatter)) scatter.tools.append(ZoomTool(scatter)) line.tools.append(PanTool(line)) line.tools.append(ZoomTool(line)) # Set the two plots' ranges to be the same scatter.range2d = line.range2d
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, *args, **kw): super(ErrorBarApp, self).__init__(*args, **kw) # Gather the values of the function and the error index_points, value_points = get_points() err_low, err_high = get_errors(value_points) # Converts to ArrayDataSource to feed the ErrorBarPlot class err_low, err_high = ArrayDataSource(err_low), ArrayDataSource(err_high) arrayplotdata = ArrayPlotData(index = index_points, value = value_points) plot = Plot(arrayplotdata) # Plot the function plot.plot(("index","value"), type = "line", color = "red") plot.title = "Cosine with errors" # Overlay the error bars: they are a 2D renderer. plot.add_xy_plot(index_name = "index", value_name = "value", renderer_factory = ErrorBarPlot, value_low = err_low, value_high = err_high, # Below are optional configuration arguments line_width = 2, color = "green", line_style = "solid", # could be 'dash', 'dot', ... endcap_size = 5, endcap_style = "bar", # could be 'none' ) self.main_plot = plot
def _create_plot_component(): # Create some data numpts = 5000 x = sort(random(numpts)) y = random(numpts) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="scatter", marker="circle", index_sort="ascending", color="orange", marker_size=3, bgcolor="white") # Tweak some of the plot properties plot.title = "Scatter Plot" plot.line_width = 0.5 plot.padding = 50 # 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) return plot
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
def __init__(self, **traits): super(ContainerExample, self).__init__(**traits) x = np.linspace(-14, 14, 100) y = np.sin(x) * x**3 / 1000 data = ArrayPlotData(x=x, y=y) p1 = Plot(data, padding=30) p1.plot(("x", "y"), type="scatter", color="blue") p1.plot(("x", "y"), type="line", color="blue") p2 = Plot(data, padding=30) p2.plot(("x", "y"), type="line", color="blue") p2.set(bounds = [200, 100], position = [70,150], bgcolor = (0.9,0.9,0.9), unified_draw=True, resizable="") p3 = Plot(data, padding=30) p3.plot(("x", "y"), type="line", color="blue", line_width=2.0) p4 = Plot(data, padding=30) p4.plot(("x", "y"), type="scatter", color="red", marker="circle") c1 = OverlayPlotContainer(p1, p2) c1.fixed_preferred_size = p3.get_preferred_size() c2 = HPlotContainer(c1, p3) c3 = VPlotContainer(p4, c2) self.plot = c3
class MyPlot(HasTraits): """ Displays a plot with a few buttons to control which overlay to display """ plot = Instance(Plot) status_overlay = Instance(StatusLayer) error_button = Button('Error') warn_button = Button('Warning') no_problem_button = Button('No problem') traits_view = View( HGroup(Item('error_button', show_label=False), Item('warn_button', show_label=False), Item('no_problem_button', show_label=False)), Item('plot', editor=ComponentEditor(), show_label=False), resizable=True) def __init__(self, index, data_series, **kw): super(MyPlot, self).__init__(**kw) plot_data = ArrayPlotData(index=index) plot_data.set_data('data_series', data_series) self.plot = Plot(plot_data) self.plot.plot(('index', 'data_series')) def _error_button_fired(self, event): """ removes the old overlay and replaces it with an error overlay """ self.clear_status() self.status_overlay = ErrorLayer(component=self.plot, align='ul', scale_factor=0.25) self.plot.overlays.append(self.status_overlay) self.plot.request_redraw() def _warn_button_fired(self, event): """ removes the old overlay and replaces it with an warning overlay """ self.clear_status() self.status_overlay = WarningLayer(component=self.plot, align='ur', scale_factor=0.25) self.plot.overlays.append(self.status_overlay) self.plot.request_redraw() def _no_problem_button_fired(self, event): """ removes the old overlay """ self.clear_status() self.plot.request_redraw() def clear_status(self): if self.status_overlay in self.plot.overlays: # fade_out will remove the overlay when its done self.status_overlay.fade_out()
def _create_plot_component(self): self.data = ArrayPlotData() self.data["frequency"] = np.linspace(0., SAMPLING_RATE/2.0, num=NUM_SAMPLES/2) for i in range(NUM_LINES): self.data['amplitude%d' % i] = np.zeros(NUM_SAMPLES/2) self.data["time"] = np.linspace(0., float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES) self.data['time_amplitude'] = np.zeros(NUM_SAMPLES) self.data['imagedata'] = np.zeros(( NUM_SAMPLES/2, SPECTROGRAM_LENGTH)) spectrum_plot = Plot(self.data) for i in range(NUM_LINES): if i==NUM_LINES-1: linewidth = 2 color = (1,0,0) else: linewidth = 1 c = (NUM_LINES-i-1)/float(NUM_LINES) color = (1, 0.5+c/2, c) spectrum_plot.plot(("frequency", "amplitude%d" % i), name="Spectrum%d" % i, color=color, line_width=linewidth) spectrum_plot.padding_bottom = 20 spectrum_plot.padding_top = 20 spec_range = list(spectrum_plot.plots.values())[0][0].value_mapper.range spec_range.low = -90 spec_range.high = 0.0 spectrum_plot.index_axis.title = 'Frequency(Hz)' spectrum_plot.value_axis.title = 'Amplitude(dB)' time_plot = Plot(self.data) time_plot.plot(("time", "time_amplitude"), name="Time", color="blue") time_plot.padding_top = 20 time_plot.padding_bottom = 20 time_plot.index_axis.title = 'Time (seconds)' time_plot.value_axis.title = 'Amplitude' time_range = list(time_plot.plots.values())[0][0].value_mapper.range time_range.low = -1.5 time_range.high = 1.5 spectrogram_plot = Plot(self.data) spectrogram_time = (0.0, SPECTROGRAM_LENGTH*NUM_SAMPLES/float(SAMPLING_RATE)) spectrogram_freq = (0.0, SAMPLING_RATE/2.0) spectrogram_plot.img_plot('imagedata', name='Spectrogram', xbounds=spectrogram_time, ybounds=spectrogram_freq, colormap=cm.reverse(cm.Blues), ) range_obj = spectrogram_plot.plots['Spectrogram'][0].value_mapper.range range_obj.high = -20 range_obj.low = -60 spectrogram_plot.padding_bottom = 20 spectrogram_plot.padding_top = 20 container = VPlotContainer() container.add(time_plot) container.add(spectrum_plot) container.add(spectrogram_plot) return container
def _create_plot_component(self): self.data = ArrayPlotData() self.data["frequency"] = np.linspace(0., SAMPLING_RATE/2.0, num=NUM_SAMPLES/2) for i in xrange(NUM_LINES): self.data['amplitude%d' % i] = np.zeros(NUM_SAMPLES/2) self.data["time"] = np.linspace(0., float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES) self.data['time_amplitude'] = np.zeros(NUM_SAMPLES) self.data['imagedata'] = np.zeros(( NUM_SAMPLES/2, SPECTROGRAM_LENGTH)) spectrum_plot = Plot(self.data) for i in xrange(NUM_LINES): if i==NUM_LINES-1: linewidth = 2 color = (1,0,0) else: linewidth = 1 c = (NUM_LINES-i-1)/float(NUM_LINES) color = (1, 0.5+c/2, c) spectrum_plot.plot(("frequency", "amplitude%d" % i), name="Spectrum%d" % i, color=color, line_width=linewidth) spectrum_plot.padding_bottom = 20 spectrum_plot.padding_top = 20 spec_range = spectrum_plot.plots.values()[0][0].value_mapper.range spec_range.low = -90 spec_range.high = 0.0 spectrum_plot.index_axis.title = 'Frequency(Hz)' spectrum_plot.value_axis.title = 'Amplitude(dB)' time_plot = Plot(self.data) time_plot.plot(("time", "time_amplitude"), name="Time", color="blue") time_plot.padding_top = 20 time_plot.padding_bottom = 20 time_plot.index_axis.title = 'Time (seconds)' time_plot.value_axis.title = 'Amplitude' time_range = time_plot.plots.values()[0][0].value_mapper.range time_range.low = -1.5 time_range.high = 1.5 spectrogram_plot = Plot(self.data) spectrogram_time = (0.0, SPECTROGRAM_LENGTH*NUM_SAMPLES/float(SAMPLING_RATE)) spectrogram_freq = (0.0, SAMPLING_RATE/2.0) spectrogram_plot.img_plot('imagedata', name='Spectrogram', xbounds=spectrogram_time, ybounds=spectrogram_freq, colormap=cm.reverse(cm.Blues), ) range_obj = spectrogram_plot.plots['Spectrogram'][0].value_mapper.range range_obj.high = -20 range_obj.low = -60 spectrogram_plot.padding_bottom = 20 spectrogram_plot.padding_top = 20 container = VPlotContainer() container.add(time_plot) container.add(spectrum_plot) container.add(spectrogram_plot) return container
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 _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 __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 get_plot(self): pixel_sizes = self.data_source.voxel_sizes shape = self.data.shape m = min(pixel_sizes) s = [int(d*sz/m) for d, sz in zip(shape, pixel_sizes)] if 1: # else physical aspect ratio is enabled ss = max(s)/4 s = [max(s,ss) for s in s] plot_sizes = dict (xy = (s[2], s[1]), xz = (s[2], s[0]), zy = (s[0],s[1]), zz=(s[0],s[0])) plots = GridContainer(shape=(2,2), spacing=(3, 3), padding = 50, aspect_ratio=1) pxy = Plot(self.plotdata, padding=1, fixed_preferred_size = plot_sizes['xy'], x_axis=PlotAxis (orientation='top'), ) pxz = Plot(self.plotdata, padding=1, fixed_preferred_size = plot_sizes['xz'], ) pzy = Plot(self.plotdata, padding=1, fixed_preferred_size = plot_sizes['zy'], #orientation = 'v', # cannot use 'v' because of img_plot assumes row-major ordering x_axis=PlotAxis(orientation='top'), y_axis=PlotAxis(orientation='right'), ) pzz = Plot(self.plotdata, padding=1, fixed_preferred_size = plot_sizes['zz']) plots.add(pxy, pzy, pxz, pzz) self.plots = dict(xy = pxy.img_plot('xy', colormap=bone)[0], xz = pxz.img_plot('xz', colormap=bone)[0], zy = pzy.img_plot('zy', colormap=bone)[0], zz = pzz.img_plot('zz')[0], xyp = pxy.plot(('z_x', 'z_y'), type='scatter', color='orange', marker='circle', marker_size=3, selection_marker_size = 3, selection_marker='circle')[0], xzp = pxz.plot(('y_x', 'y_z'), type='scatter', color='orange', marker='circle', marker_size=3, selection_marker_size = 3, selection_marker='circle')[0], zyp = pzy.plot(('x_z', 'x_y'), type='scatter', color='orange', marker='circle', marker_size=3, selection_marker_size = 3, selection_marker='circle')[0], ) for p in ['xy', 'xz', 'zy']: self.plots[p].overlays.append(ZoomTool(self.plots[p])) self.plots[p].tools.append(PanTool(self.plots[p], drag_button='right')) imgtool = ImageInspectorTool(self.plots[p]) self.plots[p].tools.append(imgtool) overlay = ImageInspectorOverlay(component=self.plots[p], bgcolor = 'white', image_inspector=imgtool) self.plots['zz'].overlays.append(overlay) self.plots[p+'p'].tools.append (ScatterInspector(self.plots[p+'p'], selection_mode = 'toggle')) self.plots['xyp'].index.on_trait_change (self._xyp_metadata_handler, 'metadata_changed') self.plots['xzp'].index.on_trait_change (self._xzp_metadata_handler, 'metadata_changed') self.plots['zyp'].index.on_trait_change (self._zyp_metadata_handler, 'metadata_changed') plot = HPlotContainer() # todo: add colormaps plot.add(plots) return 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, *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 _plot_default(self): p = Plot(self.plot_data) p.plot( ("rx", "ry"), type='line', color='red') p.plot( ("gx", "gy"), type='line', color='green') p.plot( ("bx", "by"), type='line', color='blue') p.plot( ("ax", "ay"), type='line', color='black') p.plot( ("lx", "ly"), type='line', color='black') p.plot( ("ux", "uy"), type='line', color='black') return p
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): 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): # 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 _phi_plot_default(self): data = ArrayPlotData(h=self.h_range, phi=self.phi_sample) p = Plot(data) p.plot(('h', 'phi'), type='line', name='phi', color='slateblue', line_width=2.7) p.x_axis.title = 'h' p.y_axis.title = 'Phi[h]' p.x_grid.line_color = p.y_grid.line_color = 'slategray' p.bgcolor = 'khaki' p.title = 'Nonlinearity' return p
def _create_plot_component(): # Create the index numpoints = 100 low = -5 high = 15.0 x = arange(low, high, (high - low) / numpoints) plotdata = ArrayPlotData(x=x, y1=jn(0, x), y2=jn(1, x)) # Create the left plot left_plot = Plot(plotdata) left_plot.x_axis.title = 'X' left_plot.y_axis.title = 'j0(x)' renderer = left_plot.plot(('x', 'y1'), type='line', color='blue', width=2.0)[0] renderer.overlays.append(LineInspector(renderer, axis='value', write_metadata=True, is_listener=True)) renderer.overlays.append(LineInspector(renderer, axis='index', write_metadata=True, is_listener=True)) left_plot.overlays.append(ZoomTool(left_plot, tool_mode='range')) left_plot.tools.append(PanTool(left_plot)) # Create the right plot right_plot = Plot(plotdata) right_plot.index_range = left_plot.index_range right_plot.orientation = 'v' right_plot.x_axis.title = 'j1(x)' right_plot.y_axis.title = 'X' renderer2 = right_plot.plot(('x', 'y2'), type='line', color='red', width=2.0)[0] renderer2.index = renderer.index renderer2.overlays.append(LineInspector(renderer2, write_metadata=True, is_listener=True)) renderer2.overlays.append(LineInspector(renderer2, axis='value', is_listener=True)) right_plot.overlays.append(ZoomTool(right_plot, tool_mode='range')) right_plot.tools.append(PanTool(right_plot)) container = HPlotContainer(background='lightgray') container.add(left_plot) container.add(right_plot) right_plot = Plot(plotdata) right_plot.index_range = left_plot.index_range right_plot.orientation = 'v' right_plot.x_axis.title = 'j1(x)' right_plot.y_axis.title = 'X' renderer2 = right_plot.plot(('x', 'y2'), type='line', color='red', width=2.0)[0] renderer2.index = renderer.index renderer2.overlays.append(LineInspector(renderer2, write_metadata=True, is_listener=True)) renderer2.overlays.append(LineInspector(renderer2, axis='value', is_listener=True)) right_plot.overlays.append(ZoomTool(right_plot, tool_mode='range')) right_plot.tools.append(PanTool(right_plot)) container.add(right_plot) return container
def __init__(self): super(ContainerExample, self).__init__() x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) scatter = Plot(plotdata) scatter.plot(("x", "y"), type="scatter", color="blue") line = Plot(plotdata) line.plot(("x", "y"), type="line", color="blue") container = HPlotContainer(scatter, line) self.plot = container
def makeplot( x,y,title, miny, maxy ): plotdata = ArrayPlotData(x=x, y=y ) #, y2=y2, y3=y3 ) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.title = title spec_range = plot.value_mapper.range spec_range.low = miny spec_range.high = maxy 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 _v_plot_default(self): plot = Plot(self.pd, orientation="v", resizable="v", padding=20, padding_bottom=160, default_origin="top left") plot.height = 600 plot.width = 100 plot.plot(("v_index", "v_value")) return plot
def _plot_default(self): # Create the data and the PlotData object x = linspace(-14, 14, 100) 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 scatter plot in the Plot plot.plot(("x", "y"), type="scatter", color="blue") # Add our custom tool to the plot plot.tools.append(CustomTool(plot)) return plot
def create_plot(): # Create some data numpts = 200 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" # Set colors #plot.title_color = "white" #for axis in plot.x_axis, plot.y_axis: # axis.set(title_color="white", tick_label_color="white") # 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) plot.tools.append(MoveTool(plot, drag_button="right")) return plot
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 _plot_default(self): outcomes, results, time = self._prepare_data() # get the x,y data to plot pds = [] for outcome in outcomes: pd = ArrayPlotData(index = time) result = results.get(outcome) for j in range(result.shape[0]): pd.set_data("y"+str(j), result[j, :] ) pds.append(pd) # Create a container and add our plots container = GridContainer( bgcolor="white", use_backbuffer=True, shape=(len(outcomes),1)) #plot data tools = [] for j, outcome in enumerate(outcomes): pd1 = pds[j] # Create some line plots of some of the data plot = Plot(pd1, title=outcome, border_visible=True, border_width = 1) plot.legend.visible = False a = len(pd1.arrays)- 1 if a > 1000: a = 1000 for i in range(a): plotvalue = "y"+str(i) color = colors[i%len(colors)] plot.plot(("index", plotvalue), name=plotvalue, color=color) for value in plot.plots.values(): for entry in value: entry.index.sort_order = 'ascending' # Attach the selector tools to the plot selectorTool1 = LineSelectorTool(component=plot) plot.tools.append(selectorTool1) tools.append(selectorTool1) container.add(plot) #make sure the selector tools know each other for tool in tools: a = set(tools) - set([tool]) tool._other_selectors = list(a) tool._demo = self return container
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 _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): super(IMUGloveDisplay, self).__init__() x = linspace(-14, 14, 100) y = sin(x) * x**3 plotdata = ArrayPlotData(x=x, y=y) scatter = Plot(plotdata) scatter.plot(("x", "y"), type="scatter", color="blue") line = Plot(plotdata) line.plot(("x", "y"), type="line", color="blue") container = HPlotContainer(scatter, line) #scatter.title = "sin(x) * x^3" #line.title = 'line plot' self.plot = container self.InitGlove()
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 _plot_density_default(self): plot = Plot(self.plot_density_data, padding_left=60, padding_top=25, padding_right=10, padding_bottom=50) plot.plot(('density_plot_x', 'density_plot_y'), style='line', color='blue') plot.index_axis.title = 'frequency [MHz]' plot.value_axis.title = 'spectral density [MHz]' plot.title = 'Spectral density' plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(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, *l, **kw): # TODO: implement aspect ratio maintaining HasTraits.__init__(self, *l, **kw) #self.plotdata = ArrayPlotData(x=self.pointsx, y=self.pointsy) plot = Plot(self.plotdata) plot.plot(("x", "y")) plot.plot(("x", "y"), type='scatter') plot.tools.append(PanTool(plot, drag_button='left')) plot.tools.append(ZoomTool(plot, tool_mode='box')) plot.tools.append(DragZoom(plot, tool_mode='box', drag_button='right')) plot.tools.append(CustomSaveTool( plot)) #, filename='/home/pankaj/Desktop/file.png')) plot.tools.append(TraitsTool(plot)) self.plot = plot self.set_plotdata()
def _plot_xy8norm_default(self): plot = Plot(self.plot_xy8norm_data, padding_left=60, padding_top=25, padding_right=10, padding_bottom=50) plot.plot(('xy8norm_plot_x', 'xy8norm_plot_y'), style='line', color='blue') plot.index_axis.title = 'tau [micro-s]' plot.value_axis.title = 'normalized Intensity' plot.title = 'xy8 normalized to rabi contrast' plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) plot.y_axis.mapper.range.set(low=-0.1, high=1.1) return plot
def __init__(self, title, xtitle, x, ytitle, y, type="line", color="blue"): super(LinePlot, self).__init__() plotdata = ArrayPlotData(x=x, y=y) self.plotdata = plotdata plot = Plot(self.plotdata) plot.plot(('x', 'y'), type=type, color=color) plot.title = title plot.x_axis.title = xtitle plot.y_axis.title = ytitle self.plot = plot self._hid = 0 self._colors = ['blue', 'red', 'black', 'green', 'magenta', 'yellow'] # Add some tools self.plot.tools.append(PanTool(self.plot, constrain_key="shift")) self.plot.overlays.append( ZoomTool(component=self.plot, tool_mode="box", always_on=False))
def _plot_default(self): plot = Plot(self.plotdata) self.plotdata.set_data('t', self.t) self.plotdata.set_data('x', self.x) plot.plot(('t', 'x'), color='red', type_trait="plot_type", name='x') plot.legend.visible = True plot.title = "Stopped flow" plot.x_axis.title = 't' # Add pan and zoom to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(plot) plot.overlays.append(zoom) return 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(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" plot.tools.append(PanTool(plot)) plot.tools.append( DragZoom(plot, drag_button="right", maintain_aspect_ratio=False)) plot.overlays.append(ZoomTool(plot)) # plot.overlays.append(ZoomTool(plot, tool_mode="range", axis = "index", # always_on=True, always_on_modifier="control")) self.plot = plot self.data = data
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
class HistDemo(HasTraits): plot = Instance(Plot) timer = Instance(Timer) need_update = Bool(False) view = View(Item("plot", editor=ComponentEditor(), show_label=False), resizable=True, width=500, height=250, title="Hist Demo") 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 _selection_changed(self): if self.select_tool.selection != None: self.need_update = True def on_timer(self): if self.need_update: x0, x1 = self.select_tool.selection self.img2[:] = self.img[:] np.clip(self.img2[:], x0, x1, out=self.img2[:]) self.img2[:] -= x0 self.img2[:] *= 256.0 / (x1 - x0) cv.imshow("Hist Demo", self.img2) self.need_update = False
def render_scatplot(self): peakdata = ArrayPlotData() peakdata.set_data("index", self.peaks[self.img_idx][:, 0]) peakdata.set_data("value", self.peaks[self.img_idx][:, 1]) peakdata.set_data("color", self.peaks[self.img_idx][:, 2]) scatplot = Plot(peakdata, aspect_ratio=self.img_plot.aspect_ratio, default_origin="top left") scatplot.plot( ("index", "value", "color"), type="cmap_scatter", name="my_plot", color_mapper=jet(DataRange1D(low=0.0, high=1.0)), marker="circle", fill_alpha=0.5, marker_size=6, ) scatplot.x_grid.visible = False scatplot.y_grid.visible = False scatplot.range2d = self.img_plot.range2d self.scatplot = scatplot self.peakdata = peakdata return scatplot
def __init__(self, **kw): super(CorrelationData, self).__init__(**kw) plot = Plot(self.plotdata) plot2 = Plot(self.plotdata) plot.plot(("time", "cr"), type="line", color="blue") plot2.plot(("lag", "corr"), type="line", color="green") plot2.plot(("lag", "avg"), type="line", color="red") plot2.index_scale = 'log' self.cr_plot = plot self.corr_plot = plot2
def __init__(self, **traits): super(CircleSelectionDemo, self).__init__(**traits) x = np.random.random(100)*2 y = np.random.random(100) data = ArrayPlotData(x=x, y=y) plot = Plot(data) scatter = plot.plot(("x", "y"), type="scatter", color="blue")[0] scatter.tools.append( CircleSelection(scatter) ) scatter.overlays.append( ScatterInspectorOverlay(scatter, selection_color="red", selection_marker="circle", selection_outline_color = "black", selection_marker_size = 6) ) scatter.overlays.append( CircleSelectionOverlay(scatter) ) self.plot = plot self.data = data