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 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 _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 _create_plot_component(): # Create some x-y data series to plot x = linspace(1.0, 8.0, 200) pd = ArrayPlotData(index = x) pd.set_data("y0", sqrt(x)) pd.set_data("y1", x) pd.set_data("y2", x**2) pd.set_data("y3", exp(x)) pd.set_data("y4", gamma(x)) pd.set_data("y5", x**x) # Create some line plots of some of the data plot = Plot(pd) plot.plot(("index", "y0"), line_width=2, name="sqrt(x)", color="purple") plot.plot(("index", "y1"), line_width=2, name="x", color="blue") plot.plot(("index", "y2"), line_width=2, name="x**2", color="green") plot.plot(("index", "y3"), line_width=2, name="exp(x)", color="gold") plot.plot(("index", "y4"), line_width=2, name="gamma(x)",color="orange") plot.plot(("index", "y5"), line_width=2, name="x**x", color="red") # Set the value axis to display on a log scale plot.value_scale = "log" # Tweak some of the plot properties plot.title = "Log Plot" 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 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 _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,*args, **kw): super(FieldDataController, self).__init__(*args, **kw) #self.plotdata = ArrayPlotData(x = self.model.index, y = self.model.data) self.model.intensity_map = zeros((100,100)) # Create a plot data obect and give it this data self.plot_data = ArrayPlotData() self.plot_data.set_data("imagedata", self.model.intensity_map) # Create a contour polygon plot of the data plot = Plot(self.plot_data, default_origin="top left") plot.contour_plot("imagedata", type="poly", poly_cmap=jet, name='Intensity map') # Create a contour line plot for the data, too plot.contour_plot("imagedata", type="line") # Tweak some of the plot properties plot.title = "Intensity Map" plot.padding = 50 plot.bg_color = "black" plot.fill_padding = 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) dragzoom = DragZoom(plot, drag_button="right") plot.tools.append(dragzoom) plot.tools.append(CustomTool(plot)) #plot.x_axis.title = 'Index' #plot.y_axis.title = r'Power [$\mu$W]' #self.renderer = plot.plot(("x", "y"), type="line", color="black") self.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 = "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 _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_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 __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 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, *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 index, sorted_vals = _create_data(200) # Create a plot data obect and give it this data pd = ArrayPlotData(index = index, min = sorted_vals[0], bar_min = sorted_vals[1], average = sorted_vals[2], bar_max = sorted_vals[3], max = sorted_vals[4]) # Create the plot plot = Plot(pd) plot.candle_plot(("index", "min", "bar_min", "average", "bar_max", "max"), color = "lightgray", bar_line_color = "black", stem_color = "blue", center_color = "red", center_width = 2) # Tweak some of the plot properties plot.title = "Candlestick 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 _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(): # 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 _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 _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): 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(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 _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 __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, **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 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 _create_plot_component(): # Create some data numpts = 1000 x = numpy.arange(0, numpts) y = numpy.random.random(numpts) marker_size = numpy.random.normal(4.0, 4.0, numpts) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Because this is a non-standard renderer, we can't call plot.plot, which # sets up the array data sources, mappers and default index/value ranges. # So, its gotta be done manually for now. index_ds = ArrayDataSource(x) value_ds = ArrayDataSource(y) # Create the plot plot = Plot(pd) plot.index_range.add(index_ds) plot.value_range.add(value_ds) # Create the index and value mappers using the plot data ranges imapper = LinearMapper(range=plot.index_range) vmapper = LinearMapper(range=plot.value_range) # Create the scatter renderer scatter = VariableSizeScatterPlot( index=index_ds, value=value_ds, index_mapper = imapper, value_mapper = vmapper, marker='circle', marker_size=marker_size, color=(1.0,0.0,0.75,0.4)) # Append the renderer to the list of the plot's plots plot.add(scatter) plot.plots['var_size_scatter'] = [scatter] # 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 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
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) spectrogram_time = linspace( 0.0, float(SPECTROGRAM_LENGTH * NUM_SAMPLES) / float(SAMPLING_RATE), num=SPECTROGRAM_LENGTH ) spectrogram_freq = linspace(0.0, float(SAMPLING_RATE / 2), num=NUM_SAMPLES / 2) spectrogram_plot.img_plot( "imagedata", name="Spectrogram", xbounds=spectrogram_time, ybounds=spectrogram_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 return obj.spectrum_plot, obj.time_plot, obj.spectrogram_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 _units_plot_default(self): N = min([self.N_CA, DISP_UNITS]) data = ArrayPlotData(i=numpy.arange(N), r=self.r[:N], i_aff=self.i_aff[:N]) p = Plot(data) p.plot(('i', 'r', 'i_aff'), type='cmap_scatter', color_mapper=hot, marker='circle', marker_size=3, line_width=0) p.title = 'Place Cell Output' p.x_axis.title = 'Output Units' p.y_axis.title = 'Rate / Iaff' p.value_range.set_bounds(0.0, 1.0) p.x_grid.visible = p.y_grid.visible = False p.bgcolor = 'slategray' 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 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") # Set the title plot.title = "sin(x) * x^3" # Assign it to our self.plot attribute self.plot = plot
def do_plot(name, pd): xname = name + "_x" yname = name + "_y" pd.set_data(xname, range(len(DATA[name]))) pd.set_data(yname, DATA[name]) plot = Plot(pd, padding = 30, unified_draw = True, border_visible = True, ) plot.x_axis.visible = False plot.title = name plot.plot((xname, yname), name=name, type="line", color="blue",) return plot
def _update_img_plot(self, plot_name, image, title): """Update an image plot.""" plotdata = ArrayPlotData(imagedata=image) xbounds = (0, image.shape[1] - 1) ybounds = (0, image.shape[0] - 1) plot = Plot(plotdata) plot.aspect_ratio = float(xbounds[1]) / float(ybounds[1]) plot.img_plot("imagedata", colormap=bone, xbounds=xbounds, ybounds=ybounds) plot.title = title setattr(self, plot_name, plot) getattr(self, plot_name).request_redraw()
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 _create_plot_component(): # Create some data npts = 100 x = sort(random(npts)) y = random(npts) # 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", name="my_plot", marker="circle", index_sort="ascending", color="slategray", marker_size=6, bgcolor="white") # Tweak some of the plot properties plot.title = "Scatter Plot With Selection" plot.line_width = 1 plot.padding = 50 # Right now, some of the tools are a little invasive, and we need the # actual ScatterPlot object to give to them my_plot = plot.plots["my_plot"][0] # Attach some tools to the plot my_plot.tools.append(ScatterInspector(my_plot, selection_mode="toggle", persistent_hover=False)) my_plot.overlays.append( ScatterInspectorOverlay(my_plot, hover_color = "transparent", hover_marker_size = 10, hover_outline_color = "purple", hover_line_width = 2, selection_marker_size = 8, selection_color = "lawngreen") ) my_plot.tools.append(PanTool(my_plot)) my_plot.overlays.append(ZoomTool(my_plot, drag_button="right")) return plot
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(MutiLinePlot, self).__init__(**traits) x = np.linspace(-14, 14, 100) y1 = np.sin(x) * x**3 y2 = np.cos(x) * x**3 data = ArrayPlotData(x=x, y1=y1, y2=y2) plot = Plot(data) plot.plot(("x", "y1"), type="line", color="blue", name="sin(x) * x**3") plot.plot(("x", "y2"), type="line", color="red", name="cos(x) * x**3") plot.plot(("x", "y2"), type="scatter", color="red", marker = "circle", marker_size = 2, name="cos(x) * x**3 points") plot.title = "Multiple Curves" plot.legend.visible = True self.plot = plot self.data = data
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_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 _update_img_plot(self, plot_name, image, title): """Update an image plot.""" plotdata = ArrayPlotData(imagedata=image) xbounds = (0, image.shape[1] - 1) ybounds = (0, image.shape[0] - 1) plot = Plot(plotdata) plot.aspect_ratio = float(xbounds[1]) / float(ybounds[1]) plot.img_plot("imagedata", colormap=bone, xbounds=xbounds, ybounds=ybounds) plot.title = title setattr(self, plot_name, plot) getattr(self, plot_name).request_redraw()
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, **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(MutiLinePlot, self).__init__(**traits) x = np.linspace(-14, 14, 100) y1 = np.sin(x) * x**3 y2 = np.cos(x) * x**3 data = ArrayPlotData(x=x, y1=y1, y2=y2) plot = Plot(data) plot.plot(("x", "y1"), type="line", color="blue", name="sin(x) * x**3") plot.plot(("x", "y2"), type="line", color="red", name="cos(x) * x**3") plot.plot(("x", "y2"), type="scatter", color="red", marker="circle", marker_size=2, name="cos(x) * x**3 points") plot.title = "Multiple Curves" plot.legend.visible = True self.plot = plot self.data = data
def __init__(self): super(LinePlot, self).__init__() x = linspace(-14, 14, 100) y1 = sin(x) * x**3 y2 = cos(x) * x**3 plotdata = ArrayPlotData(x=x, y1=y1, y2=y2) plot = Plot(plotdata) plot.plot(("x", "y1"), type="line", color="blue", name="sin(x) * x**3") plot.plot(("x", "y2"), type="line", color="red", name="cos(x) * x**3") plot.plot(("x", "y2"), type="scatter", color="red", marker="circle", marker_size=2, name="cos(x) * x**3 points") plot.title = "Multiple Curves" self.plot = plot legend = Legend(padding=10, align="ur") legend.plots = plot.plots plot.overlays.append(legend)
def _plot_default(self): self._pd = ArrayPlotData() self._pd.set_data("imagedata", self._image) plot = Plot(self._pd, default_origin="top left") plot.x_axis.orientation = "top" img_plot = plot.img_plot("imagedata")[0] plot.bgcolor = "white" # Tweak some of the plot properties plot.title = "Click to add points, press Enter to clear selection" plot.padding = 50 plot.line_width = 1 # Attach some tools to the plot pan = PanTool(plot, drag_button="right", constrain_key="shift") plot.tools.append(pan) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component(): # Create a scalar field to contour xs = linspace(-2 * pi, 2 * pi, 600) ys = linspace(-1.5 * pi, 1.5 * pi, 300) x, y = meshgrid(xs, ys) z = tanh(x * y / 6) * cosh(exp(-y**2) * x / 3) z = x * y # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create a contour polygon plot of the data plot = Plot(pd, default_origin="top left") plot.contour_plot("imagedata", type="poly", poly_cmap=jet, xbounds=(xs[0], xs[-1]), ybounds=(ys[0], ys[-1])) # Create a contour line plot for the data, too plot.contour_plot("imagedata", type="line", xbounds=(xs[0], xs[-1]), ybounds=(ys[0], ys[-1])) # Tweak some of the plot properties plot.title = "My First Contour Plot" plot.padding = 50 plot.bg_color = "white" plot.fill_padding = 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 get_plot(self): #pd = ArrayPlotData() index_label = 'index' index = None colors = ['purple','blue','green','gold', 'orange', 'red', 'black'] groups = defaultdict(lambda:[]) pd = ArrayPlotData() index_values = None if 'relative time' in self.table: index_key = 'relative time' index_values = self.table[index_key] else: index_key = 'index' index_label = index_key for key, values in self.table.items(): if index_values is None: index_values = range(len(values)) if key==index_label: continue if key.startswith('stage '): label = key[6:].strip() group = groups['stages'] elif key=='contact position': label = key group = groups['stages'] elif key.startswith('fiber '): if key.endswith('deformation'): label = key[5:-11].strip() group = groups['fiber deformation'] elif key.endswith('position'): label = key[5:-8].strip() group = groups['fiber position'] else: label = key[5:].strip () group = groups['fiber'] elif key.startswith('sarcomere '): label = key[10:].strip() if label=='orientation': # this is artificial information continue group = groups['sarcomere'] else: label = key group = groups[key] group.append((index_label, label, index_key, key)) pd.set_data(key, values) pd.set_data (index_key, index_values) if 'force' in self.table and 'stage right current' in self.table: group = groups['position-force'] group.append(('position','force','stage right current','force')) n = len (groups) if n in [0,1,2,3,5,7]: shape = (n, 1) elif n in [4,6,8,10]: shape = (n//2,2) elif n in [9]: shape = (n//3,3) else: raise NotImplementedError (`n`) container = GridContainer(padding=10, #fill_padding=True, #bgcolor="lightgray", use_backbuffer=True, shape=shape, spacing=(0,0)) for i, (group_label, group_info) in enumerate(groups.items ()): plot = Plot (pd) for j, (index_label, label, index_key, key) in enumerate(group_info): color = colors[j % len (colors)] plot.plot((index_key, key), name=label, color=color, x_label=index_label) plot.legend.visible = True plot.title = group_label plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) container.add (plot) return container
def _update_spline_plot(self): """Update the spline plot.""" knots = np.mgrid[0:1:((self.num_internal_knots + 2) * 1j)][1:-1] medial_repr = self.current_object.aligned_version.medial_repr dependent_variable = np.mgrid[0:1:(medial_repr.length * 1j)] laplacian = ndimage.gaussian_laplace(medial_repr.width_curve, self.smoothing, mode='constant', cval=np.nan) m_spline = LSQUnivariateSpline(dependent_variable, medial_repr.medial_axis, knots) w_spline = LSQUnivariateSpline(dependent_variable, medial_repr.width_curve, knots) # sample at double the frequency spl_dep_var = np.mgrid[0:1:(medial_repr.length * 2j)] plots = self.plots if plots is None: # Render the plot for the first time. plotdata = ArrayPlotData( medial_x=dependent_variable, medial_y=medial_repr.medial_axis, width_x=dependent_variable, width_y=medial_repr.width_curve, medial_spline_x=spl_dep_var, medial_spline_y=m_spline(spl_dep_var), width_spline_x=spl_dep_var, width_spline_y=w_spline(spl_dep_var), laplacian_y=laplacian, ) plot = Plot(plotdata) # Width data self._width_data_renderer, = plot.plot( ("width_x", "width_y"), type="line", color="blue", name="Original width curve data") filterdata = ArrayPlotData(x=dependent_variable, laplacian=laplacian) filterplot = Plot(filterdata) self._laplacian_renderer, = filterplot.plot( ("x", "laplacian"), type="line", color="black", name="Laplacian-of-Gaussian") # Titles for plot & axes plot.title = "Width curves" plot.x_axis.title = "Normalized position on medial axis" plot.y_axis.title = "Fraction of medial axis width" # Legend mangling stuff legend = plot.legend plot.legend = None legend.set(component=None, visible=True, resizable="", auto_size=True, bounds=[250, 70], padding_top=plot.padding_top) filterlegend = filterplot.legend filterplot.legend = None filterlegend.set(component=None, visible=True, resizable="", auto_size=True, bounds=[250, 50], padding_top=filterplot.padding_top) self.plots = GridPlotContainer(plot, legend, filterplot, filterlegend, shape=(2, 2), valign="top", bgcolor="transparent") else: # Update the real width curve self._width_data_renderer.index.set_data(dependent_variable) self._width_data_renderer.value.set_data(medial_repr.width_curve) # Render the Laplacian self._laplacian_renderer.index.set_data(dependent_variable) self._laplacian_renderer.value.set_data(laplacian)