def _setup_plot_tools(self, plot): """Sets up the background, and several tools on a plot""" # Make a white background with grids and axes plot.bgcolor = "white" add_default_grids(plot) add_default_axes(plot) # Allow white space around plot plot.index_range.tight_bounds = False plot.index_range.refresh() plot.value_range.tight_bounds = False plot.value_range.refresh() # The PanTool allows panning around the plot plot.tools.append(PanTool(plot)) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # The DragZoom tool just zooms in and out as the user drags # the mouse vertically. dragzoom = DragZoom(plot, drag_button="right") plot.tools.append(dragzoom) # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) return plot.value_mapper, plot.index_mapper, legend
def _add_line_legend(self): # Add a legend in the upper right corner, and make it relocatable legend = Legend( component=self, padding=10, align="ur", plots=self.plots, ) legend.tools.append(LegendTool(legend, drag_button="right")) self.overlays.append(legend)
def _select_angle_names_changed(self): for _myos_in in range(2): self.stream_Angle[_myos_in] = deque(np.zeros(self.Angle_length)) self.plot_Angle = Plot(self.data_Angle) self.plot_Angle.auto_colors = ['blue', 'red'] for _pic in self.select_angle_names: self.plot_Angle.plot(('x', ) + (_pic, ), name=_pic, color='auto') self.plot_Angle.title = 'Multiple Angle' _legend = Legend(padding=10, align="ur") _legend.plots = self.plot_Angle.plots self.plot_Angle.overlays.append(_legend)
def gen_line_plot(series_one, series_two, y_axis_name=''): """ Parameters ---------- series_one : nd array series_two : nd array """ size = min(series_one.shape[0], series_two.shape[0]) idx = ArrayDataSource(arange(size)) series_one_data = ArrayDataSource(series_one[:size]) series_two_data = ArrayDataSource(series_two[:size]) y_range = DataRange1D(series_one_data) y_range.tight_bounds = False y_range.margin = 50 x_mapper = LinearMapper(range=DataRange1D(idx)) y_mapper = LinearMapper(range=y_range) series_one_plot = LinePlot(index=idx, value=series_one_data, index_mapper=x_mapper, value_mapper=y_mapper, color='blue') series_two_plot = LinePlot(index=idx, value=series_two_data, index_mapper=x_mapper, value_mapper=y_mapper, color='red') container = OverlayPlotContainer(bgcolor='white', padding=25, fill_padding=False, border_visible=True) y_axis = PlotAxis(mapper=y_mapper, component=container, orientation='left') x_axis = PlotAxis(mapper=x_mapper, component=container, orientation='bottom') x_axis.title = 'Time' y_axis.title = y_axis_name legend = Legend(component=container, padding=10, align='ur') legend.plots = { 'Predicted': series_one_plot, 'Actual': series_two_plot, } container.add(series_one_plot) container.add(series_two_plot) container.overlays.append(y_axis) container.overlays.append(legend) return container
def _create_plot_component_vertical(signals=Array, use_downsampling=False): # container = HPlotContainer(resizable = "hv", bgcolor="lightgray", # fill_padding=True, padding = 10) container = VPlotContainer(resizable="hv", bgcolor="lightgray", fill_padding=True, padding=50) nSignal, nSample = np.shape(signals) time = arange(nSample) value_range = None plots = {} for i in range(nSignal): plot = create_line_plot( (time, signals[i]), color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]), width=1.0, # orientation="v") orientation="h") plot.origin_axis_visible = True # plot.origin = "top left" plot.padding_left = 10 plot.padding_right = 10 plot.border_visible = False plot.bgcolor = "white" if value_range is None: value_range = plot.value_mapper.range else: plot.value_range = value_range value_range.add(plot.value) container.add(plot) plots["Corr fun %d" % i] = plot # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) legend.plots = plots # container.padding_top = 50 container.overlays.append( PlotLabel("Correlation function", component=container, font="swiss 16", overlay_position="top")) # selection_overlay = RangeSelectionOverlay(component=plot) # plot.tools.append(RangeSelection(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) # plot.overlays.append(selection_overlay) plot.overlays.append(zoom) return container
def _select_emg_names_changed(self): for chanel in range(8): self.stream_emg[chanel] = deque(np.zeros(self.sEMG_length)) self.plot_EMG = Plot(self.data_EMG) self.plot_EMG.auto_colors = [ 'green', 'lightgreen', 'blue', 'lightblue', 'red', 'pink', 'darkgray', 'silver' ] for pic in self.select_emg_names: self.plot_EMG.plot(('x', ) + (pic, ), name=pic, color='auto') self.plot_EMG.title = 'Multiple sEMG' legend = Legend(padding=10, align="ur") legend.plots = self.plot_EMG.plots self.plot_EMG.overlays.append(legend)
def _add_frame_legend(self): class DummyPlot(LinePlot): line_width = 10.0 dp = {"p < 0.001": DummyPlot(color=(1.0, 0.0, 0.0)), "p < 0.01": DummyPlot(color=(1.0, 0.65, 0.0)), "p < 0.05": DummyPlot(color=(1.0, 1.0, 0.0)), "p >= 0.05": DummyPlot(color=(0.5, 0.5, 0.5))} legend = Legend( component=self, padding=10, border_padding=10, align="lr", bgcolor="white", title="Frame legend", plots=dp, ) self.overlays.append(legend)
def plotParsedData(self): self.plotdata = ArrayPlotData(x = self.data["ts"], wrdlt = self.data["wrdlt"]) self.plotA = Plot(self.plotdata) self.plotAA = self.plotA.plot(("x", "wrdlt"), type="line", color=(0,0.99,0), spacing=0, padding=0, alpha=0.7, use_downsampling=True, line_style = "dash") #render_style='connectedhold' # cache default axes limits self.Arng = [ self.plotA.x_axis.mapper.range.low, self.plotA.x_axis.mapper.range.high, self.plotA.y_axis.mapper.range.low, self.plotA.y_axis.mapper.range.high] self.plotA.x_axis.tick_label_position="inside" self.plotA.y_axis.tick_label_position="inside" self.container = VPlotContainer(self.plotA, spacing=0, padding=0, bgcolor="lightgray", use_backbuffer = True) self.plotA.spacing = 0 # set child padding after container set! self.plotA.padding = 0 self.plotA.tools.append(PanTool(self.plotA)) self.plotA.tools.append(ZoomTool(self.plotA)) self.plotA.overlays.append(BetterSelectingZoom(self.plotA)) legend = Legend(component=self.plotA, padding=1, align="ur") # to hide plots, make LegendHighlighter scale line to 0 on selection legend.tools.append(LegendHighlighter(legend, line_scale=0.0)) self.plots = {} self.plots["wrdlt"] = self.plotAA legend.plots = self.plots self.plotA.overlays.append(legend)
def _setup_plot(self): self.plot_data = ArrayPlotData() self.plot = MyPlotClass(self.plot_data, padding_left=120, fill_padding=True, bgcolor="white", use_backbuffer=True) self._setup_plot_tools(self.plot) # Recreate the legend so it sits on top of the other tools. self.plot.legend = Legend(component=self.plot, padding=10, error_icon='blank', visible=False, scrollable=True, plots=self.plots,clip_to_component=True) self.plot.legend.tools.append(LegendTool(self.plot.legend, drag_button="right")) self.plot.x_axis = MyPlotAxis(component=self.plot, orientation='bottom') self.plot.y_axis = MyPlotAxis(component=self.plot, orientation='left') self.plot.x_axis.title = ur'Angle (2\u0398)' tick_font = settings.tick_font self.plot.x_axis.title_font = settings.axis_title_font self.plot.y_axis.title_font = settings.axis_title_font self.plot.x_axis.tick_label_font = tick_font self.plot.y_axis.tick_label_font = tick_font #self.plot.x_axis.tick_out = 0 #self.plot.y_axis.tick_out = 0 self._set_scale('linear') # Add the traits inspector tool to the container self.plot.tools.append(TraitsTool(self.plot))
def create_hplot(self, key=None, mini=False): if mini: hpc = HPlotContainer(bgcolor='darkgrey', height=MINI_HEIGHT, resizable='h', padding=0) else: hpc = HPlotContainer(bgcolor='lightgrey', padding=HPLOT_PADDING, resizable='hv') # make slice plot for showing intesity profile of main plot #************************************************************ slice_plot = Plot(self.data, width=SLICE_PLOT_WIDTH, orientation="v", resizable="v", padding=MAIN_PADDING, padding_left=MAIN_PADDING_LEFT, bgcolor='beige', origin='top left') slice_plot.x_axis.visible = False slice_key = key + '_slice' ydata_key = key + '_y' slice_plot.plot((ydata_key, slice_key), name=slice_key) # make main plot for editing depth lines #************************************************************ main = Plot( self.data, border_visible=True, bgcolor='beige', origin='top left', padding=MAIN_PADDING, padding_left=MAIN_PADDING_LEFT, ) if mini: main.padding = MINI_PADDING # add intensity img to plot and get reference for line inspector #************************************************************ img_plot = main.img_plot(key, name=key, xbounds=self.model.xbounds[key], ybounds=self.model.ybounds[key], colormap=self._cmap)[0] # add line plots: use method since these may change #************************************************************ self.update_line_plots(key, main, update=True) # set slice plot index range to follow main plot value range #************************************************************ slice_plot.index_range = main.value_range # add vertical core lines to main plots and slices #************************************************************ # save pos and distance in session dict for view info and control for core in self.model.core_samples: loc_index, loc, dist = self.model.core_info_dict[core.core_id] # add boundarys to slice plot ref_line = self.model.final_lake_depth self.plot_core_depths(slice_plot, core, ref_line, loc_index) # add positions to main plots self.plot_core(main, core, ref_line, loc_index, loc) # now add tools depending if it is a mini plot or not #************************************************************ if mini: # add range selection tool only # first add a reference line to attach it to reference = self.make_reference_plot() main.add(reference) # attache range selector to this plot range_tool = RangeSelection(reference) reference.tools.append(range_tool) range_overlay = RangeSelectionOverlay(reference, metadata_name="selections") reference.overlays.append(range_overlay) range_tool.on_trait_change(self._range_selection_handler, "selection") # add zoombox to mini plot main.plot(('zoombox_x', 'zoombox_y'), type='polygon', face_color=ZOOMBOX_COLOR, alpha=ZOOMBOX_ALPHA) # add to hplot and dict hpc.add(main) self.hplot_dict['mini'] = hpc else: # add zoom tools main.tools.append(PanTool(main)) zoom = ZoomTool(main, tool_mode='box', axis='both', alpha=0.5) main.tools.append(zoom) main.overlays.append(zoom) main.value_mapper.on_trait_change(self.zoom_all_value, 'updated') main.index_mapper.on_trait_change(self.zoom_all_index, 'updated') # add line inspector and attach to freeze tool #********************************************* line_inspector = LineInspector(component=img_plot, axis='index_x', inspect_mode="indexed", is_interactive=True, write_metadata=True, metadata_name='x_slice', is_listener=True, color="white") img_plot.overlays.append(line_inspector) self.inspector_freeze_tool.tool_set.add(line_inspector) # add listener for changes to metadata made by line inspector #************************************************************ img_plot.on_trait_change(self.metadata_changed, 'index.metadata') # set slice plot index range to follow main plot value range #************************************************************ slice_plot.index_range = main.value_range # add clickable legend ; must update legend when depth_dict updated #****************************************************************** legend = Legend(component=main, padding=0, align="ur", font='modern 8') legend_highlighter = LegendHighlighter(legend, drag_button="right") legend.tools.append(legend_highlighter) self.update_legend_plots(legend, main) legend.visible = False self.legend_dict[key] = [legend, legend_highlighter] main.overlays.append(legend) # add main and slice plot to hplot container and dict #**************************************************** main.title = 'frequency = {} kHz'.format(key) main.title_font = TITLE_FONT hpc.add(main, slice_plot) self.hplot_dict[key] = hpc return hpc
def _create_plot_component(): container = OverlayPlotContainer(padding=50, fill_padding=True, bgcolor="lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = arange(low, high + 0.001, (high - low) / numpoints) # Plot some bessel functions plots = {} broadcaster = BroadcasterTool() for i in range(4): y = jn(i, x) plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.index.sort_order = "ascending" plot.bgcolor = "white" plot.border_visible = True if i == 0: add_default_grids(plot) add_default_axes(plot) # Create a pan tool and give it a reference to the plot it should # manipulate, but don't attach it to the plot. Instead, attach it to # the broadcaster. pan = PanTool(plot) broadcaster.tools.append(pan) container.add(plot) plots["Bessel j_%d" % i] = plot # Add an axis on the right-hand side that corresponds to the second plot. # Note that it uses plot.value_mapper instead of plot0.value_mapper. plot1 = plots["Bessel j_1"] axis = PlotAxis(plot1, orientation="right") plot1.underlays.append(axis) # Add the broadcast tool to the container, instead of to an # individual plot container.tools.append(broadcaster) legend = Legend(component=container, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) container.overlays.append(legend) # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append( PlotLabel("Bessel functions", component=container, font="swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container
def _create_plot_component(): container = OverlayPlotContainer( padding=50, fill_padding=True, bgcolor="lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = linspace(low, high, numpoints) now = time() timex = linspace(now, now + 7 * 24 * 3600, numpoints) # Plot some bessel functions value_mapper = None index_mapper = None plots = {} for i in range(10): y = jn(i, x) if i % 2 == 1: plot = create_line_plot( (timex, y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.index.sort_order = "ascending" else: plot = create_scatter_plot( (timex, y), color=tuple(COLOR_PALETTE[i])) plot.bgcolor = "white" plot.border_visible = True if i == 0: value_mapper = plot.value_mapper index_mapper = plot.index_mapper left, bottom = add_default_axes(plot) left.tick_generator = ScalesTickGenerator() bottom.tick_generator = ScalesTickGenerator( scale=CalendarScaleSystem()) add_default_grids(plot, tick_gen=bottom.tick_generator) else: plot.value_mapper = value_mapper value_mapper.range.add(plot.value) plot.index_mapper = index_mapper index_mapper.range.add(plot.index) if i == 0: plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) container.add(plot) plots["Bessel j_%d" % i] = plot # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append( PlotLabel( "Bessel functions", component=container, font="swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container
def build_plot(self): print 'Building plot...' fitrange = self.fitrange # Just for convenience onearray = Array onearray = sp.ones(self.indata.shape[0]) minuses = onearray * (-1.) # Define index array for fit function: self.mod_x = sp.arange(self.line_center - 50., self.line_center + 50., .01) self.Model = sp.zeros(self.mod_x.shape[0]) # Establish continuum array in a way that opens for other, more # elaborate continua. self.contarray = sp.ones(self.mod_x.shape[0]) * \ self.Components['Contin'][0] self.y = {} for comp in self.CompoList: self.y[comp] = gauss( # x, mu, sigma, amplitude self.mod_x, self.Components[comp][0] + self.line_center, self.Components[comp][1], self.Components[comp][2]) self.Model = self.contarray + self.y[self.select] broca = BroadcasterTool() # Define the part of the data to show in initial view: plotrange = sp.where((self.x > self.line_center - 30) & (self.x < self.line_center + 30)) # Define the y axis max value in initial view (can be panned/zoomed): maxval = float(self.indata[fitrange].max() * 1.2) minval = maxval / 15. minval = abs(np.median(self.indata[fitrange])) * 1.5 maxerr = self.errs[fitrange].max() * 1.3 resmin = max(sp.absolute(self.Resids[self.fitrange]).max(), 5.) * 1.2 cenx = sp.array([self.line_center, self.line_center]) ceny = sp.array([-minval, maxval]) cenz = sp.array([-maxval, maxval]) # Gray shading of ignored ranges rangelist = np.array(self.rangelist) grayx = np.array(rangelist.flatten().repeat(2)) grayx = np.hstack((self.x.min(), grayx, self.x.max())) grayy = np.ones_like(grayx) * self.indata.max() * 2. grayy[1::4] = -grayy[1::4] grayy[2::4] = -grayy[2::4] grayy = np.hstack((grayy[-1], grayy[:-1])) # Build plot of data and model self.plotdata = ArrayPlotData( wl=self.x, data=self.indata, xs=self.mod_x, cont=self.contarray, ones=onearray, minus=minuses, model=self.Model, errors=self.errs, ceny=ceny, cenz=cenz, cenx=cenx, Residuals=self.Resids, grayx=grayx, grayy=grayy, ) # Add dynamically created components to plotdata for comp in self.CompoList: self.plotdata.set_data(comp, self.y[comp]) olplot = GridContainer(shape=(2, 1), padding=10, fill_padding=True, bgcolor='transparent', spacing=(5, 10)) plot = Plot(self.plotdata) plot.y_axis.title = 'Flux density' resplot = Plot(self.plotdata, tick_visible=True, y_auto=True) resplot.x_axis.title = u'Wavelength [Å]' resplot.y_axis.title = u'Residuals/std. err.' # Create initial plot: Spectrum data, default first component, # default total line profile. self.comprenders = [] self.datarender = plot.plot(('wl', 'data'), color='black', name='Data', render_style='connectedhold') self.contrender = plot.plot(('xs', 'cont'), color='darkgray', name='Cont') self.modlrender = plot.plot(('xs', 'model'), color='blue', line_width=1.6, name='Model') self.centrender = plot.plot(('cenx', 'ceny'), color='black', type='line', line_style='dot', name='Line center', line_width=1.) self.rangrender = plot.plot( ('grayx', 'grayy'), type='polygon', face_color='lightgray', edge_color='gray', face_alpha=0.3, alpha=0.3, ) # There may be an arbitrary number of gaussian components, so: print 'Updating model' for comp in self.CompoList: self.comprenders.append( plot.plot( ('xs', comp), type='line', color=Paired[self.Components[comp] [3]], # tuple(COLOR_PALETTE[self.CompNum]), line_color=Paired[self.Components[comp][ 3]], # tuple(COLOR_PALETTE[self.CompNum]), line_style='dash', name=comp)) # Create panel with residuals: resplot.plot(('wl', 'Residuals'), color='black', name='Resids') resplot.plot(('wl', 'ones'), color='green') resplot.plot(('wl', 'minus'), color='green') resplot.plot(('cenx', 'cenz'), color='red', type='line', line_style='dot', line_width=.5) resplot.plot( ('grayx', 'grayy'), # Yes, that one again type='polygon', face_color='lightgray', edge_color='gray', face_alpha=0.3, alpha=0.3, ) plot.x_axis.visible = False # Set ranges to change automatically when plot values change. plot.value_range.low_setting,\ plot.value_range.high_setting = (-minval, maxval) plot.index_range.low_setting,\ plot.index_range.high_setting = (self.line_center - 30., self.line_center + 30.) resplot.value_range.low_setting,\ resplot.value_range.high_setting = (-resmin, resmin) resplot.index_range.low_setting,\ resplot.index_range.high_setting = (plot.index_range.low_setting, plot.index_range.high_setting) #resplot.index_range = plot.index_range # Yes or no? FIXME plot.overlays.append( ZoomTool(plot, tool_mode='box', drag_button='left', always_on=False)) resplot.overlays.append( ZoomTool(resplot, tool_mode='range', drag_button='left', always_on=False)) # List of renderers to tell the legend what to write self.plots['Contin'] = self.contrender self.plots['Center'] = self.centrender self.plots['Model'] = self.modlrender for i in sp.arange(len(self.comprenders)): self.plots[self.CompoList[i]] = self.comprenders[i] # Build Legend: legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) legend.plots = self.plots plot.overlays.append(legend) olplot.tools.append(broca) pan = PanTool(plot) respan = PanTool(resplot, constrain=True, constrain_direction='x') broca.tools.append(pan) broca.tools.append(respan) plot.overlays.append(ZoomTool(plot, tool_mode='box', always_on=False)) olplot.add(plot) olplot.add(resplot) olplot.components[0].set(resizable='hv', bounds=[500, 400]) olplot.components[1].set(resizable='h', bounds=[500, 100]) self.plot = plot self.resplot = resplot self.plwin = olplot self.legend = legend self.plotrange = plotrange
def _create_plot_component(): container = OverlayPlotContainer(padding=60, fill_padding=True, use_backbuffer=True, border_visible=True) # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = arange(low, high + 0.001, (high - low) / numpoints) # Plot some bessel functions plots = {} broadcaster = BroadcasterTool() for i in range(4): y = jn(i, x) plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0) if i == 0: add_default_grids(plot) left_axis, _ = add_default_axes(plot) left_axis.title = "Bessel j0, j2, j3" elif i != 1: # Map correctly j2 and j3 on the first plot's axis: plot0 = plots["Bessel j_0"] plot.index_mapper = plot0.index_mapper plot.value_mapper = plot0.value_mapper plot0.value_mapper.range.add(plot.value) # Create a pan/zoom tool and give it a reference to the plot it should # manipulate, but don't attach it to the plot. Instead, attach it to # the broadcaster. Do it only for each independent set of axis_mappers: if i in [0, 1]: pan = PanTool(component=plot) broadcaster.tools.append(pan) zoom = ZoomTool(component=plot) broadcaster.tools.append(zoom) container.add(plot) plots["Bessel j_%d" % i] = plot # Add an axis on the right-hand side that corresponds to the second plot. # Note that it uses plot.value_mapper instead of plot0.value_mapper. plot1 = plots["Bessel j_1"] axis = PlotAxis(plot1, orientation="right") plot1.underlays.append(axis) axis.title = "Bessel j1" # Add the broadcast tool to one of the renderers: adding it to the # container instead breaks the box mode of the ZoomTool: plot0 = plots["Bessel j_0"] plot0.tools.append(broadcaster) # Create a legend, with tools to move it around and highlight renderers: legend = Legend(component=container, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) legend.tools.append(LegendHighlighter(legend)) container.overlays.append(legend) # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append( PlotLabel("Bessel functions", component=container, font="swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container
def _plot_PC(self, set_id, PCx=1, PCy=2): # Adds a PC plot rendrer to the plot object # FIXME: Value validation # sending to metadata for get_x_y_status if PCx < 1 or PCx > self.data.n_pc or PCy < 1 or PCy > self.data.n_pc: raise Exception( "PC x:{}, y:{} for plot axis is out of range:{}".format( PCx, PCy, self.data.n_pc)) self.data.x_no, self.data.y_no = PCx, PCy markers = [ 'dot', 'square', 'triangle', 'circle', 'inverted_triangle', 'cross' ] pdata = self.data.plot_data[set_id - 1] plots = {} if self.data.plot_group: # FIXME: To be replace by next elif clause group = self.data.plot_group subsets = pdata.pc_ds.get_subsets(group) for ci, ss in enumerate(subsets): # 's{}pc{}g{}c{}'.format(set_n+1, (j+1), gn, ss.id) x_id = 's{}pc{}g{}c{}'.format(set_id, PCx, group, ss.id) y_id = 's{}pc{}g{}c{}'.format(set_id, PCy, group, ss.id) # plot definition pd = (x_id, y_id) # plot name pn = 'plot_{}_class_{}'.format(set_id, ss.id) # plot rl = self.plot(pd, type='scatter', name=pn, marker=markers[set_id - 1 % 5], marker_size=2, color=ss.gr_style.fg_color) labels = ss.row_selector color = ss.gr_style.fg_color self._add_plot_data_labels(rl[0], pd, labels, color) plots[ss.name] = rl[0] legend = Legend(component=self, plots=plots, padding=10, align="ur") self.overlays.append(legend) elif self.data.coloring_factor is not None: facname = self.data.coloring_factor.name for lvn, lv in self.data.coloring_factor.levels.iteritems(): # "ds{0}:fc{1}:lv{2}:pc{3}".format(set_id, facname, lv.name, i) x_id = 'ds{0}:fc{1}:lv{2}:pc{3}'.format( set_id, facname, lvn, PCx) y_id = 'ds{0}:fc{1}:lv{2}:pc{3}'.format( set_id, facname, lvn, PCy) # plot definition pd = (x_id, y_id) # plot name pn = 'plot_{}_class_{}'.format(set_id, lvn) # plot rl = self.plot(pd, type='scatter', name=pn, marker=markers[set_id - 1 % 5], marker_size=2, color=lv.color) labels = lv.get_labels(pdata.pc_ds, axis=0) color = lv.color self._add_plot_data_labels(rl[0], pd, labels, color) # Plot the rest of the points as black # "ds{0}:fc{1}:lv{2}:pc{3}".format(set_id, facname, lv.name, i) x_id = 'ds{0}:fc{1}:lv{2}:pc{3}'.format(set_id, facname, 'not', PCx) y_id = 'ds{0}:fc{1}:lv{2}:pc{3}'.format(set_id, facname, 'not', PCy) # plot definition pd = (x_id, y_id) # plot name pn = 'plot_{}_class_{}'.format(set_id, 'not') # plot rl = self.plot(pd, type='scatter', name=pn, marker=markers[set_id - 1 % 5], marker_size=2, color=pdata.color) labels = self.data.coloring_factor.get_rest_labels(pdata.pc_ds) color = pdata.color self._add_plot_data_labels(rl[0], pd, labels, color) else: # Typical id: ('s1pc1', 's1pc2') x_id = 's{}pc{}'.format(set_id, PCx) y_id = 's{}pc{}'.format(set_id, PCy) # plot definition pd = (x_id, y_id) # plot name pn = 'plot_{}_class_0'.format(set_id) # plot rl = self.plot( pd, type='scatter', name=pn, marker=markers[set_id - 1 % 5], marker_size=2, # color=self.data.plot_data[set_id-1].color ) # adding data labels labels = pdata.labels color = pdata.color self._add_plot_data_labels(rl[0], pd, labels, color) # Add Lasso selection if available # my_plot = self.plots["plot_1_class_0"][0] if hasattr(self, 'overlay_selection'): self.overlay_selection(rl[0]) # Set axis title self._set_plot_axis_title()