def plotImage(self, image, title, plot): '''plot one image image: 2d ndarray or ssp matrix title: string, plot title plot: plot instance to be update, if None, a plot instance will be created return: plot instance''' if plot == None: pd = ArrayPlotData() pd.set_data('imagedata', image) plot = Plot(pd, default_origin = "bottom left") plot.title = title plot.bgcolor = 'white' if not title == 'Total Intensity': plot.x_axis.visible = False plot.y_axis.visible = False imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0] # TODO: mess with color maps on else block else: imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0] self._appendTools(imgPlot, title) else: plot.data.set_data('imagedata', image) plot.title = title plot.aspect_ratio = float(image.shape[1]) / image.shape[0] plot.invalidate_draw() return plot
def _plot_default(self): # Set up the spectrum plot spectrum_plot = Plot(self.spectrum_data) spectrum_plot.plot(("frequency", "amplitude"), name="Spectrum", color="red") spectrum_plot.padding = 50 spectrum_plot.title = "Spectrum" spec_range = list( spectrum_plot.plots.values())[0][0].value_mapper.range # noqa spec_range.low = 0.0 spec_range.high = 5.0 spectrum_plot.index_axis.title = 'Frequency (Hz)' spectrum_plot.value_axis.title = 'Amplitude' # Time series plot time_plot = Plot(self.time_data) time_plot.plot(("time", "amplitude"), name="Time", color="blue") time_plot.padding = 50 time_plot.title = "Time" 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 = -0.2 time_range.high = 0.2 # Spectrogram plot spectrogram_plot = Plot(self.spectrogram_plotdata) max_time = SPECTROGRAM_LENGTH * NUM_SAMPLES / SAMPLING_RATE max_freq = SAMPLING_RATE / 2 spectrogram_plot.img_plot( 'imagedata', name='Spectrogram', xbounds=(0, max_time), ybounds=(0, max_freq), colormap=hot, ) range_obj = spectrogram_plot.plots['Spectrogram'][0].value_mapper.range range_obj.high = 5 range_obj.low = 0.0 spectrogram_plot.title = 'Spectrogram' container = HPlotContainer() container.add(spectrum_plot) container.add(time_plot) container.add(spectrogram_plot) return container
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(): # 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 _create_plot_component(): # Create some data numpts = 5000 x = sort(random(numpts)) y = random(numpts) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Create the plot plot = Plot(pd) # 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_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 _create_plot_component(): # Create some data index, vals = _create_data(20) # Create a plot data object and give it this data pd = ArrayPlotData(index = index, values = vals) # Create the plot plot = Plot(pd) plot.stacked_bar_plot(("index", "values"), color = ["red", "yellow", "green", "blue"], outline_color = "lightgray",) # Tweak some of the plot properties plot.title = "Stacked Bar 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(): # Load state data states = pandas.read_csv('states.csv') lon = (states['longitude'] + 180.) / 360. lat = numpy.radians(states['latitude']) lat = (1 - (1. - numpy.log(numpy.tan(lat) + (1. / numpy.cos(lat))) / numpy.pi) / 2.0) populations = pandas.read_csv('state_populations.csv') data = populations['2010'] lon = lon.view(numpy.ndarray) lat = lat.view(numpy.ndarray) data = data.view(numpy.ndarray) plot = Plot(ArrayPlotData(index=lon, value=lat, color=data)) renderers = plot.plot( ("index", "value", "color"), type="cmap_scatter", name="unfunded", color_mapper=OrRd, marker="circle", outline_color='lightgray', line_width=1., marker_size=10, ) tile_cache = MBTileManager(filename='./map.mbtiles', min_level=2, max_level=4) # Need a better way add the overlays cmap = renderers[0] map = Map(cmap, tile_cache=tile_cache, zoom_level=3) cmap.underlays.append(map) plot.title = "2010 Population" plot.tools.append(PanTool(plot)) plot.tools.append(ZoomTool(plot)) plot.index_axis.title = "Longitude" plot.index_axis.tick_label_formatter = convert_lon plot.value_axis.title = "Latitude" plot.value_axis.tick_label_formatter = convert_lat cmap.overlays.append( ColormappedSelectionOverlay(cmap, fade_alpha=0.35, selection_type="mask")) colorbar = create_colorbar(plot.color_mapper) colorbar.plot = cmap colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom container = HPlotContainer(use_backbuffer=True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" return container
def _create_plot(self, max, min, dataobj, title): x = dataobj[:,0] y = dataobj[:,1] if y.max()>max: max = y.max() if y.min()<min: min = y.min() if self.sample_size>1: y2 = dataobj[:,6] y3 = dataobj[:,7] if y3.max()>max: max = y3.max() if y2.min()<min: min = y2.min() plotdata = ArrayPlotData(x=x, y=y, y2=y2, y3=y3) else: plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") if self.sample_size>1: plot.plot(("x", "y2"), type="line", color="red") plot.plot(("x", "y3"), type="line", color="red") plot.title = title plot.title_font = 'Arial 10' return plot, max, min
def _plot_default(self): data = ArrayPlotData(x=self.model.x, y=self.model.y) plot = Plot(data) plot.plot(('x', 'y'), style='line', color='green') plot.value_range.set_bounds(-self.model.a, self.model.a) plot.title = "a * exp(-b*x) * cos(omega*x + phase)" return plot
def _space_plot_default(self): self.debug_print('_space_plot_default') p = Plot(self.plot_data) # Plot track underlay x_outer, y_outer = np.transpose(n_gon((0, 0), OUTER_DIAMETER / 2, 48)) x_inner, y_inner = np.transpose(n_gon((0, 0), INNER_DIAMETER / 2, 48)) self.plot_data['x_outer'] = x_outer self.plot_data['y_outer'] = y_outer self.plot_data['x_inner'] = x_inner self.plot_data['y_inner'] = y_inner self.data_to_keep.extend(['x_outer', 'y_outer', 'x_inner', 'y_inner']) p.plot(('x_outer', 'y_outer'), type='polygon', edge_width=1.0, edge_color='darkgrey', face_color='linen') p.plot(('x_inner', 'y_inner'), type='polygon', edge_width=1.0, edge_color='darkgrey', face_color='white') p.plot(('pause_x', 'pause_y'), **PAUSE_FMT) p.plot(('scan_x', 'scan_y'), **SCAN_FMT) p.plot(('x', 'y')) p.plot(('cl_x', 'cl_y'), **SPIKE_FMT) p.title = 'Space' p.x_axis.title = 'X (cm)' p.y_axis.title = 'Y (cm)' p.padding_bottom = 55 p.range2d.set_bounds((-50, -50), (50, 50)) return p
def _create_plot(self, max, min, dataobj, title): x = dataobj[:, 0] y = dataobj[:, 1] if y.max() > max: max = y.max() if y.min() < min: min = y.min() if self.sample_size > 1: y2 = dataobj[:, 6] y3 = dataobj[:, 7] if y3.max() > max: max = y3.max() if y2.min() < min: min = y2.min() plotdata = ArrayPlotData(x=x, y=y, y2=y2, y3=y3) else: plotdata = ArrayPlotData(x=x, y=y) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") if self.sample_size > 1: plot.plot(("x", "y2"), type="line", color="red") plot.plot(("x", "y3"), type="line", color="red") # plot.padding_right = 45 # plot.padding_left = 25 # plot.padding_top = 25 # plot.padding_bottom = 25 plot.title = title plot.title_font = "Arial 10" return plot, max, min
def _plot_default(self): data = ArrayPlotData(x=self.model.x, y=self.model.y) plot = Plot(data) plot.plot(("x", "y"), style="line", color="green") plot.value_range.set_bounds(-self.model.a, self.model.a) plot.title = "a * exp(-b*x) * cos(omega*x + phase)" return plot
def _plot_default(self): # Create a GridContainer to hold all of our plots: 2 rows, 4 columns: container = GridContainer(fill_padding=True, bgcolor="lightgray", use_backbuffer=True, shape=(2, 4)) arrangements = [('top left', 'h'), ('top right', 'h'), ('top left', 'v'), ('top right', 'v'), ('bottom left', 'h'), ('bottom right', 'h'), ('bottom left', 'v'), ('bottom right', 'v')] orientation_name = {'h': 'horizontal', 'v': 'vertical'} pd = ArrayPlotData(image=lena()) # Plot some bessel functions and add the plots to our container for origin, orientation in arrangements: plot = Plot(pd, default_origin=origin, orientation=orientation) plot.img_plot('image') # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) title = '{0}, {1}' plot.title = title.format(orientation_name[orientation], origin.replace(' ', '-')) # Add to the grid container container.add(plot) return container
def _create_plot_component(): # Create some data numpts = 1000 x = sort(random(numpts)) y = random(numpts) color = randint(0, 7, numpts) # 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=accent, 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 with Range-selectable Data Points" 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 _plot_default(self): plot = Plot(self.plotdata) plot.plot(("x", "y"), color="green") plot.title = "A*x**2 + B*x + C" plot.x_axis.title = "x" plot.y_axis.title = "y" return plot
def createPlot(self, showDataTag ): # picks the desired channel out of the interleaved data stride = self.header.getChannels() # the first sample contains the data tag - the user has the # option to not display with the offset enabled offset = 0 if showDataTag else stride # we first grab the entire table and then select 1st ipp # along with the associated channel we're interested in. # I'm assuming this slice is a reference of the original. self.dataView = self.header.getBuffer()[ 0, offset::stride ] i = self.dataView['real'] q = self.dataView['imag'] xAxis = range( offset, i.size ) plotData = ArrayPlotData( xAxis=xAxis, i=i , q=q ) plot = Plot( plotData ) plot.plot( ("xAxis", "i"), type="line", color="blue") plot.plot( ("xAxis", "q"), type="line", color="red") plot.title = 'IQ Plot' return plot
def plot_spectrum(self,x,y,field): for i in range(len(self.x_koords)): x_gap=abs(x-self.x_koords[i]) y_gap=abs(y-self.y_koords[i]) if x_gap <self.toleranz and y_gap<self.toleranz: spectrum=self.spectra[i] wavelength=self.ivCamera.create_wavelength_for_plotting() xm = [self.plotrangemarker,self.plotrangemarker] #for red line in plot ym = [0,16000] #self.plotrangey plotdata = ArrayPlotData(x=wavelength, y=spectrum,xm=xm,ym=ym) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.x_axis.title="Wavelength [nm]" plot.y_axis.title="Counts" #catch error if apd counts not loaded try: apd_counts = str(self.apd_counts[i]) except: apd_counts = str("0") plot.title = 'spectrum of QD ' +str(self.x_koords[i])+' '+str(self.y_koords[i])+' with APD at '+str(apd_counts) plot.overlays.append(ZoomTool(component=plot,tool_mode="box", always_on=False)) # damit man im Plot zoomen kann plot.tools.append(PanTool(plot, constrain_key="shift")) # damit man mit der Maus den Plot verschieben kann if field=='current': self.plot_current=plot if self.plotsetalways: self._plotrangeset_fired() if field=='compare': self.plot_compare=plot if self.plotsetalways: self._plotrangeset_fired()
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) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="scatter", marker="circle", index_sort="ascending", color=(1.0, 0.0, 0.74, 0.4), marker_size=marker_size, 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 _plot_default(self): self.data = self._data_default() plot = Plot(self.data) for ii, s_name in enumerate(self._samples): color = COLORS[ii % len(self._samples)] plot.plot( ("bins", s_name), name=s_name, type="filled_line", edge_color=color, face_color=color, alpha=0.5, bgcolor="white", render_style="hold", ) # render_style determines whether interpolate plot.index = plot._get_or_create_datasource("bins") # set index name manually so range selection works plot.index_scale = "log" plot.title = "Fermi Plot" plot.padding = 50 plot.legend.visible = True plot.tools.append(PanTool(plot)) plot.active_tool = RangeSelection(plot) plot.overlays.append(RangeSelectionOverlay(component=plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component(): # Use n_gon to compute center locations for our polygons points = n_gon(center=(0,0), r=3, nsides=4) # Choose some colors for our polygons colors = {3:0xaabbcc, 4:'orange', 5:'yellow', 6:'lightgreen'} # Create a PlotData object to store the polygon data pd = ArrayPlotData() # Create a Polygon Plot to draw the regular polygons polyplot = Plot(pd) # Store path data for each polygon, and plot nsides = 3 for p in points: npoints = n_gon(center=p, r=2, nsides=nsides) nxarray, nyarray = transpose(npoints) pd.set_data("x" + str(nsides), nxarray) pd.set_data("y" + str(nsides), nyarray) plot = polyplot.plot(("x"+str(nsides), "y"+str(nsides)), type="polygon", face_color=colors[nsides], hittest_type="poly")[0] plot.tools.append(DataspaceMoveTool(plot, drag_button="left")) nsides = nsides + 1 # Tweak some of the plot properties polyplot.padding = 50 polyplot.title = "Polygon Plot" polyplot.x_axis.mapper.range.set(low=-10, high=10) polyplot.y_axis.mapper.range.set(low=-10, high=10) return polyplot
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 _plot_default(self): plot = Plot(self.plotdata) plot.title = "Simplex on the Rosenbrock function" plot.img_plot("background", name="background", xbounds=(0,1.5), ybounds=(0,1.5), colormap=jet(DataRange1D(low=0,high=100)), ) plot.plot(("values_x", "values_y"), type="scatter", color="red") background = plot.plots["background"][0] colormap = background.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=background, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom container = HPlotContainer(use_backbuffer = True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" 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=viridis)[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(): # Create some data numpts = 500 x1 = random(numpts) y1 = random(numpts) x2 = x1 + standard_normal(numpts) * 0.05 y2 = y1 + standard_normal(numpts) * 0.05 # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", column_stack([x1, x2]).reshape(-1)) pd.set_data("value", column_stack([y1, y2]).reshape(-1)) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="segment", color="forestgreen", line_width=2, line_style='dash', alpha=0.7, bgcolor="white") # Tweak some of the plot properties plot.title = "Segment 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 __init__(self, x, y, *args, **kw): super(MyPlot, self).__init__(*args, **kw) 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 _plot_default(self): self.data = self._data_default() plot = Plot(self.data) for ii, s_name in enumerate(self._samples): color = COLORS[ii % len(self._samples)] plot.plot(('bins',s_name), name=s_name, type='filled_line', edge_color=color, face_color=color, alpha=0.5, bgcolor='white', render_style='hold') # render_style determines whether interpolate plot.index = plot._get_or_create_datasource('bins') #set index name manually so range selection works plot.index_scale = 'log' plot.title = 'Fermi Plot' plot.padding = 50 plot.legend.visible = True plot.tools.append(PanTool(plot)) plot.active_tool = RangeSelection(plot) plot.overlays.append(RangeSelectionOverlay(component=plot)) zoom = ZoomTool(component=plot, tool_mode='box', always_on=False) plot.overlays.append(zoom) return plot
def _fuel_cycle_plot_component(x, y, x_name, y_name): # Create some data # 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="line", marker="circle", index_sort="ascending", color="red", marker_size=3, bgcolor="white") # Tweak some of the plot properties plot.title = "Fuel Cycle Plot" plot.line_width = 0.5 plot.padding = 100 plot.x_axis.title = x_name plot.x_axis.title_font = "Roman 16" plot.x_axis.tick_label_font = "Roman 12" plot.y_axis.title = y_name plot.y_axis.title_font = "Roman 16" plot.y_axis.tick_label_font = "Roman 12" # 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 update_show_curve(self): plotdata = ArrayPlotData(x=self.ct_hu, y=self.re_electronic_density) plot = Plot(plotdata) plot.plot(("x", "y"), type="line", color="blue") plot.title = self.name self.plot = plot
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(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 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, 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 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) pd.set_data("value2", y * 2) # 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") plot.plot(("index", "value2"), type="scatter", name="my_plot", marker="circle", index_sort="ascending", color="red", 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 _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_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) color = numpy.random.random(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) color_ds = ArrayDataSource(color) # 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 = ColormappedScatterPlot( index=index_ds, value=value_ds, color_data=color_ds, color_mapper=jet(range=DataRange1D( low=0.0, high=1.0)), fill_alpha=0.4, index_mapper=imapper, value_mapper=vmapper, marker='circle', marker_size=marker_size) # 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 = "Variable Size and Color 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_component(self): """ Creates the plot component of the to be used in the FeatureScatter instance. """ x = np.zeros(len(self.data)) y = np.zeros(len(self.data)) c = np.zeros(len(self.data)) for i, (coord, count) in enumerate(self.data.items()): x[i], y[i] = coord c[i] = count c = np.log2(c) pd = ArrayPlotData() pd.set_data("x", x) pd.set_data("y", y) pd.set_data("color", c) cm = Map(DataRange1D(low=-c.max() / 2, high=c.max())) plot = Plot(pd) plot.plot(("x", "y", "color"), type="cmap_scatter", name="my_plot", marker="dot", index_sort="ascending", color_mapper=cm, marker_size=2, bgcolor=0xF7F7F7, ) plot.title = "Scatter Plot With Lasso Selection" plot.line_width = 1 plot.padding = 50 my_plot = plot.plots["my_plot"][0] my_plot.data = self.data my_plot.out_file = self.out_file my_plot.label = self.label lasso_selection = FeatureLasso(component=my_plot, selection_datasource=my_plot.index, drag_button="left") my_plot.tools.append(lasso_selection) my_plot.tools.append(BetterZoom(my_plot, zoom_factor=1.2)) my_plot.tools.append(PanTool(my_plot, drag_button="right")) my_plot.tools.append(ScatterInspector(my_plot)) lasso_overlay = LassoOverlay(lasso_selection=lasso_selection, component=my_plot, selection_fill_color=0xEF8A62) my_plot.overlays.append(lasso_overlay) my_plot.overlays.append(ScatterInspectorOverlay(my_plot, hover_marker_size=4)) return plot
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 _plot_default(self): 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" return plot
def _plot_default (self): 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" 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) color = numpy.random.random(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) color_ds = ArrayDataSource(color) # 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 = ColormappedScatterPlot( index=index_ds, value=value_ds, color_data=color_ds, color_mapper=jet(range=DataRange1D(low=0.0, high=1.0)), fill_alpha=0.4, index_mapper = imapper, value_mapper = vmapper, marker='circle', marker_size=marker_size) # 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 = "Variable Size and Color 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_component(): # Load state data states = pandas.read_csv('states.csv') lon = (states['longitude'] + 180.) / 360. lat = numpy.radians(states['latitude']) lat = (1 - (1. - numpy.log(numpy.tan(lat) + (1./numpy.cos(lat)))/numpy.pi)/2.0) populations = pandas.read_csv('state_populations.csv') data = populations['2010'] lon = lon.view(numpy.ndarray) lat = lat.view(numpy.ndarray) data = data.view(numpy.ndarray) plot = Plot(ArrayPlotData(index = lon, value=lat, color=data)) renderers = plot.plot(("index", "value", "color"), type = "cmap_scatter", name = "unfunded", color_mapper = OrRd, marker = "circle", outline_color = 'lightgray', line_width = 1., marker_size = 10, ) tile_cache = MBTileManager(filename = './map.mbtiles', min_level = 2, max_level = 4) # Need a better way add the overlays cmap = renderers[0] map = Map(cmap, tile_cache=tile_cache, zoom_level=3) cmap.underlays.append(map) plot.title = "2010 Population" plot.tools.append(PanTool(plot)) plot.tools.append(ZoomTool(plot)) plot.index_axis.title = "Longitude" plot.index_axis.tick_label_formatter = convert_lon plot.value_axis.title = "Latitude" plot.value_axis.tick_label_formatter = convert_lat cmap.overlays.append( ColormappedSelectionOverlay(cmap, fade_alpha=0.35, selection_type="mask")) colorbar = create_colorbar(plot.color_mapper) colorbar.plot = cmap colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom container = HPlotContainer(use_backbuffer = True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" return container
def __init__(self, **traits): super(MYOGrapher, self).__init__(**traits) data_EMG = ArrayPlotData(x=[0], sEMG1=[0], sEMG2=[0], sEMG3=[0], sEMG4=[0], sEMG5=[0], sEMG6=[0], sEMG7=[0], sEMG8=[0]) data_Angle = ArrayPlotData(x=[0], myo1=[0], myo2=[0]) plot_Angle = Plot(data_Angle) plot_EMG = Plot(data_EMG) plot_EMG.plot(("x", "sEMG1"), type="line") plot_EMG.title = "sEMG" plot_EMG.value_scale = 'linear' plot_Angle.plot(("x", "myo1"), type="line") plot_Angle.title = "Angle" plot_Angle.value_scale = 'linear' self.plot_EMG = plot_EMG self.data_EMG = data_EMG self.plot_Angle = plot_Angle self.data_Angle = data_Angle self.sEMG_names = [ 'sEMG1', 'sEMG2', 'sEMG3', 'sEMG4', 'sEMG5', 'sEMG6', 'sEMG7', 'sEMG8' ] self.Angle_names = ['myo1', 'myo2'] self.emg_posit = 0 self.angle_posit = 0 _stream_emg = [] _stream_angle = [] for chanel in range(8): _stream_emg.append(np.zeros(self.sEMG_length)) self.stream_emg = _stream_emg for _myos_in in range(2): _stream_angle.append(np.zeros(self.Angle_length)) self.stream_emg = _stream_emg self.stream_Angle = _stream_angle self.EMG_StreamWin = np.zeros(self.window_size) self.Angle_StreamWin = np.zeros(self.window_size)
def _plot_default(self): x = np.linspace(-14, 14, 100) y = np.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' return plot
def _time_plot_default(self): self.debug_print('_time_plot_default') p = Plot(self.plot_data) p.plot(('time', 'ordinate')) p.plot(('cl_time', 'cl_ordinate'), **SPIKE_FMT) p.title = 'Time' p.x_axis.title = 'Time (s)' p.padding_bottom = 55 return p
def _create_plot_component(): # Generate some data for the eye diagram. num_samples = 5000 samples_per_symbol = 24 y = demo_data(num_samples, samples_per_symbol) # Compute the eye diagram array. ybounds = (-0.25, 1.25) grid = grid_count(y, 2 * samples_per_symbol, offset=16, size=(480, 480), bounds=ybounds).T # Convert the array to floating point, and replace 0 with np.nan. # These points will be transparent in the image plot. grid = grid.astype(np.float32) grid[grid == 0] = np.nan #--------------------------------------------------------------------- # The rest of the function creates the chaco image plot. pd = ArrayPlotData() pd.set_data("eyediagram", grid) plot = Plot(pd) img_plot = plot.img_plot("eyediagram", xbounds=(0, 2), ybounds=ybounds, bgcolor=(0, 0, 0), colormap=cool)[0] # Tweak some of the plot properties plot.title = "Eye Diagram" plot.padding = 50 # Axis grids vgrid = PlotGrid(component=plot, mapper=plot.index_mapper, orientation='vertical', line_color='gray', line_style='dot') hgrid = PlotGrid(component=plot, mapper=plot.value_mapper, orientation='horizontal', line_color='gray', line_style='dot') plot.underlays.append(vgrid) plot.underlays.append(hgrid) # Add pan and zoom tools. plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False) img_plot.overlays.append(zoom) return plot
def _plot_default(self): """ Set up the plot """ # Create a plot and hook it up to the data it will represent plot = Plot(self.plotdata) # Add a line plot showing y as a function of x plot.plot(("x","y"), type = "line", color = "blue") plot.title = "param * sin(x)*x**3" return plot
def _create_plot_component(obj, cqtkernel): # Scale plot scale_data = zeros((OCTAVES * BINS, FRAMES_PER_PLOT)) obj.scale_plotdata = ArrayPlotData() obj.scale_plotdata.set_data('scaleimagedata', scale_data) scale_plot = Plot(obj.scale_plotdata) max_time = float(FRAMES_PER_PLOT * 2**(OCTAVES-1) * cqtkernel.FFTLen) / SAMPLING_RATE max_note_index = OCTAVES * BINS scale_plot.img_plot('scaleimagedata', name = 'Scale', xbounds=(0, max_time), ybounds=(0, max_note_index), colormap=hot, ) scale_range = scale_plot.plots['Scale'][0].value_mapper.range scale_range.high = 5 scale_range.low = 0.0 scale_plot.title = 'Scale' obj.scale_plot = scale_plot # CQT plot cqt_data = zeros((OCTAVES * BINS, FRAMES_PER_PLOT)) obj.cqt_plotdata = ArrayPlotData() obj.cqt_plotdata.set_data('cqtimagedata', cqt_data) cqt_plot = Plot(obj.cqt_plotdata) max_time = float(FRAMES_PER_PLOT * 2**(OCTAVES-1) * cqtkernel.FFTLen) / SAMPLING_RATE max_note_index = OCTAVES * BINS cqt_plot.img_plot('cqtimagedata', name = 'CQT', xbounds=(0, max_time), ybounds=(0, max_note_index), colormap=hot, ) cqt_range = cqt_plot.plots['CQT'][0].value_mapper.range cqt_range.high = 5 cqt_range.low = 0.0 cqt_plot.title = 'CQT' obj.cqt_plot = cqt_plot container = HPlotContainer() container.add(obj.scale_plot) container.add(obj.cqt_plot) return container