def _create_corr_plot(self): plot = Plot(self.plotdata, padding=0) plot.padding_left = 25 plot.padding_bottom = 25 plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) self.corr_plot = plot
def __init__(self): super(HHCurrentTraits, self).__init__() # gates self.vm = linspace(-120,65,1000) (M, N, H) = self.__gates() nA = self.__iv() self.gatedata = ArrayPlotData(x=self.vm, M=M, N=N, H=H) self.ivdata = ArrayPlotData(x=self.vm, nA=nA) gateplot = Plot(self.gatedata) gateplot.plot(("x", "M"), type = "line", color = "blue") gateplot.plot(("x", "N"), type = "line", color = "green") gateplot.plot(("x", "H"), type = "line", color = "red") ivplot = Plot(self.ivdata) ivplot.plot(("x", "nA"), type = "line", color = "black") container = VPlotContainer(ivplot, gateplot) container.spacing = 0 gateplot.x_axis.orientation = "top" gateplot.padding_bottom = 0 ivplot.padding_top = 0 self.plots = container
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 _signals_plot_default(self): print('_signals_plot_default') """Create the Plot instance.""" plot = Plot() plot.add(self.signals_renderer) x_axis = PlotAxis(component=plot, mapper=self.signals_renderer.index_mapper, orientation='bottom') # y_axis = PlotAxis(component=plot, # mapper=self.signals_renderer.value_mapper, # orientation='left') plot.overlays.extend([x_axis]) plot.origin_axis_visible = False plot.padding_top = 0 plot.padding_left = 0 plot.padding_right = 0 plot.padding_bottom = 50 plot.border_visible = False plot.bgcolor = "white" plot.use_downsampling = True 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 _behavior_plot_default(self): self.debug_print('_behavior_plot_default') p = Plot(self.plot_data) p.plot(('abscissa', 'ordinate'), type='scatter', marker='dot', marker_size=2.0, line_width=0, color='black') p.plot(('cl_abscissa', 'cl_ordinate'), **SPIKE_FMT) p.title = 'Behavior' p.padding_bottom = 55 return p
def _plot_default(self): container = Plot(self.model.plot_data, ) container.renderer_map['bar'] = SelectableBarPlot container.padding_left = 100 container.padding_bottom = 150 # container.plot(('x', 'y'), type='bar') self.zoom_tool = ZoomTool(container, ) container.underlays.append(self.zoom_tool) container.tools.append(self.zoom_tool) self.pan_tool = PanTool(container, ) container.tools.append(self.pan_tool) return container
def _plot_default(self): container = Plot( self.model.plot_data, ) container.renderer_map['bar'] = SelectableBarPlot container.padding_left = 100 container.padding_bottom = 150 # container.plot(('x', 'y'), type='bar') self.zoom_tool = ZoomTool( container, ) container.underlays.append(self.zoom_tool) container.tools.append(self.zoom_tool) self.pan_tool = PanTool( container, ) container.tools.append(self.pan_tool) return container
def __init__(self, ExprmntVm=None, ExprmntnA=None): super(HHCurrentTraits, self).__init__() # gates self.vm = linspace(-120,65,1000) ((MCur1,NCur1,HCur1),(MCur2,NCur2,HCur2)) = self.__gates() self.Cur1gatedata = ArrayPlotData(x=self.vm, M=MCur1, N=NCur1, H=HCur1) self.Cur2gatedata = ArrayPlotData(x=self.vm, M=MCur2, N=NCur2, H=HCur2) Cur1gatesplot = Plot(self.Cur1gatedata) Cur1gatesplot.plot(("x", "M"), type = "line", color = "blue") Cur1gatesplot.plot(("x", "N"), type = "line", color = "green") Cur1gatesplot.plot(("x", "H"), type = "line", color = "red") Cur2gatesplot = Plot(self.Cur2gatedata) Cur2gatesplot.plot(("x", "M"), type = "line", color = "blue") Cur2gatesplot.plot(("x", "N"), type = "line", color = "green") Cur2gatesplot.plot(("x", "H"), type = "line", color = "red") (Cur1,Cur2) = self.__iv() self.ivdata = ArrayPlotData(x=self.vm, nA1=Cur1, nA2=Cur2, combin=Cur1+Cur2) ivplot = Plot(self.ivdata) ivplot.plot(("x", "nA1"), type = "line", color = "blue") ivplot.plot(("x", "nA2"), type = "line", color = "green") ivplot.plot(("x", "combin"), type = "line", color = "black") if ExprmntVm is not None: self.ivdata.set_data('ExptVm',ExprmntVm) self.ivdata.set_data('ExptnA',ExprmntnA) ivplot.plot(("ExptVm", "ExptnA"), type = "scatter", color = "red", marker_size = 5) self.plots = VPlotContainer(ivplot, Cur2gatesplot, Cur1gatesplot) self.plots.spacing = 0 ivplot.padding_top = 0 Cur1gatesplot.padding_bottom = 0 Cur2gatesplot.padding_top = 0 self.write_button = Button(label="Print_Pars")
def _create_1D1_plot(self): index = 0 plot0 = Plot(self.plotdata, padding=0) plot0.padding_left = 5 plot0.padding_bottom = 5 Container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) y1 = range(len(self.PCAData.batchs[0].prescores)) points = [] for batch in self.PCAData.batchs: if (self.active_scores_combobox == "Post Scores"): x1 = self.PCAData.batchs[index].postscores else: x1 = self.PCAData.batchs[index].prescores if (self.Shape == self.phenotypes[0]): a = 1 elif (self.Shape == self.phenotypes[1]): a = batch.number elif (self.Shape == self.phenotypes[2]): a = batch.type else: a = 0 if (self.Color == self.phenotypes[0]): b = 0 elif(self.Color == self.phenotypes[1]): b = batch.number elif(self.Color == self.phenotypes[2]): b = batch.type else: b = 0 tmarker = shapes[a] bcolor = self.colors[b] for i in range(len(x1)): points.append((x1[i],y1[i])) plot0 = create_scatter_plot((x1,y1), marker = tmarker, color=getColor(bcolor)) if batch.isSelected: plot0.alpha = 1 else: plot0.alpha = 0.2 plot0.bgcolor = "white" plot0.border_visible = True if index == 0: value_mapper = plot0.value_mapper index_mapper = plot0.index_mapper add_default_grids(plot0) add_default_axes(plot0, vtitle='PCA Indices', htitle='PCA Scores') plot0.index_range.tight_bounds = False plot0.index_range.refresh() plot0.value_range.tight_bounds = False plot0.value_range.refresh() plot0.tools.append(PanTool(plot0)) zoom = ZoomTool(plot0, tool_mode="box", always_on=False, maintain_aspect_ratio=False) plot0.overlays.append(zoom) dragzoom = DragZoom(plot0, drag_button="right", maintain_aspect_ratio=False) plot0.tools.append(dragzoom) else: plot0.value_mapper = value_mapper value_mapper.range.add(plot0.value) plot0.index_mapper = index_mapper index_mapper.range.add(plot0.index) Container.add(plot0) index = index +1 self.RightPlot = Container
def create_hplot(self, key=None, mini=False): if mini: hpc = HPlotContainer(bgcolor='darkgrey', height=MINI_HEIGHT, resizable='h', padding=HPLOT_PADDING ) 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, padding_bottom=MAIN_PADDING_BOTTOM, bgcolor='beige', origin='top left' ) mini_slice = Plot(self.data, width=SLICE_PLOT_WIDTH, orientation="v", resizable="v", padding=MAIN_PADDING, padding_left=MAIN_PADDING_LEFT, padding_bottom=MAIN_PADDING_BOTTOM, bgcolor='beige', origin='top left' ) slice_plot.x_axis.visible = True slice_key = key + '_slice' ydata_key = key + '_y' slice_plot.plot((ydata_key, slice_key), name=slice_key) # make plot to show line at depth of cursor. y values constant slice_depth_key = key + '_depth' slice_plot.plot(('slice_depth_depth', 'slice_depth_y'), name=slice_depth_key, color='red') self.update_slice_depth_line_plot(slice_plot, depth=0) # 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, padding_bottom=MAIN_PADDING_BOTTOM ) if mini: #main.padding = MINI_PADDING main.padding_bottom = MINI_PADDING_BOTTOM # 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) self.plot_mask_array(key, main) # 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: # add boundarys to slice plot self.plot_core_depths(slice_plot, core, ref_depth_line=None) # add positions to main plots self.plot_core(main, core, ref_depth_line=None) # 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) main.plots['reference'] = [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, mini_slice) self.hplot_dict['mini'] = hpc else: # add zoom tools zoom = ZoomTool(main, tool_mode='box', axis='both', alpha=0.5, drag_button="left") main.tools.append(zoom) main.overlays.append(zoom) self.zoom_tools[key] = 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.legend_dict[key] = [legend, legend_highlighter] self.update_legend_plots(legend, main) legend.visible = False main.overlays.append(legend) legend_highlighter.on_trait_change(self.legend_moved, '_drag_state') # add pan tool pan_tool = PanTool(main, drag_button="right") main.tools.append(pan_tool) self.pan_tool_dict[key] = pan_tool # 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(): army_lat = np.column_stack([army['start_lat'], army['end_lat']]).reshape(-1) army_lon = np.column_stack([army['start_lon'], army['end_lon']]).reshape(-1) plot_data = ArrayPlotData( army_lon=army_lon, army_lat=army_lat, army_size=army['size'], army_color=army['direction'] * army["group"], towns_lat=towns['lat'], towns_lon=towns['lon'], towns=towns['town'], temp_lon=temperatures['lon'], temp=temperatures['temp'], temp_date=temperatures['date'], ) map_plot = Plot(plot_data) map_plot.x_grid = None map_plot.y_grid = None map_plot.x_axis.orientation = 'top' map_plot.x_axis.title = 'Longitude' map_plot.y_axis.title = 'Latitude' map_plot.title = "Minard's Map of Napoleon's Russian Campaign" map_plot._title.overlay_position = "inside top" map_plot._title.hjustify = "left" map_plot._title.vjustify = "bottom" map_plot.plot( ("army_lon", "army_lat", "army_color", "army_size"), type="cmap_segment", name="my_plot", color_mapper=viridis, border_visible=True, bgcolor="white", size_min=1.0, size_max=128.0, ) map_plot.plot( ("towns_lon", "towns_lat"), type="scatter", ) map_plot.plot( ("towns_lon", "towns_lat", "towns"), type="text", text_margin=4, h_position='right', text_offset=(4, 0), ) map_plot.plot_1d( ('temp_lon'), type='line_scatter_1d', alpha=0.5, line_style='dot', ) map_plot.index_range.high_setting = 38 map_plot.index_range.low_setting = 23 map_plot.value_range.high_setting = 56.0 map_plot.value_range.low_setting = 53.5 map_plot.tools.extend([ PanTool(map_plot), ZoomTool(map_plot), ]) temp_plot = Plot(plot_data, height=100) temp_plot.index_range = map_plot.index_range temp_plot.x_grid = None temp_plot.x_axis = None temp_plot.y_axis.orientation = 'right' temp_plot.y_axis.title = u'Temp (°Re)' temp_plot.plot( ('temp_lon', 'temp'), type='line', ) temp_plot.plot_1d( ('temp_lon'), type='line_scatter_1d', alpha=0.5, line_style='dot', ) temp_plot.plot_1d( ('temp_lon', 'temp_date'), type='textplot_1d', alpha=0.5, line_style='dot', alignment='bottom', ) temp_plot.value_range.high_setting = 5 temp_plot.value_range.low_setting = -35 container = VPlotContainer(temp_plot, map_plot) container.spacing = 0 map_plot.padding_bottom = 0 map_plot.padding_left = 70 map_plot.padding_right = 70 map_plot.padding_top = 50 temp_plot.padding_top = 0 temp_plot.padding_bottom = 15 temp_plot.padding_right = 70 temp_plot.padding_left = 70 temp_plot.height = 100 temp_plot.resizable = 'h' return container
def _create_1D1_plot(self): index = 0 plot0 = Plot(self.plotdata, padding=0) plot0.padding_left = 5 plot0.padding_bottom = 5 Container = OverlayPlotContainer(padding=50, fill_padding=True, bgcolor="lightgray", use_backbuffer=True) y1 = range(len(self.PCAData.batchs[0].prescores)) points = [] for batch in self.PCAData.batchs: if (self.active_scores_combobox == "Post Scores"): x1 = self.PCAData.batchs[index].postscores else: x1 = self.PCAData.batchs[index].prescores '''if (self.Shape == self.phenotypes[0]): a = 1 elif (self.Shape == self.phenotypes[1]): a = batch.number elif (self.Shape == self.phenotypes[2]): a = batch.type else: a = 0 if (self.Color == self.phenotypes[0]): b = 0 elif(self.Color == self.phenotypes[1]): b = batch.number elif(self.Color == self.phenotypes[2]): b = batch.type else: b = 0 ''' a = batch.type b = batch.number tmarker = shapes[a] bcolor = self.colors[b] for i in range(len(x1)): points.append((x1[i], y1[i])) plot0 = create_scatter_plot((x1, y1), marker=tmarker, color=getColor(bcolor)) if batch.isSelected: plot0.alpha = 1 plot0.alpha = 1 else: plot0.fill_alpha = 0.2 plot0.edge_alpha = 0.2 plot0.bgcolor = "white" plot0.border_visible = True if index == 0: value_mapper = plot0.value_mapper index_mapper = plot0.index_mapper add_default_grids(plot0) add_default_axes(plot0, vtitle='PCA Indices', htitle='PCA Scores') plot0.index_range.tight_bounds = False plot0.index_range.refresh() plot0.value_range.tight_bounds = False plot0.value_range.refresh() plot0.tools.append(PanTool(plot0)) zoom = ZoomTool(plot0, tool_mode="box", always_on=False, maintain_aspect_ratio=False) plot0.overlays.append(zoom) dragzoom = DragZoom(plot0, drag_button="right", maintain_aspect_ratio=False) plot0.tools.append(dragzoom) else: plot0.value_mapper = value_mapper value_mapper.range.add(plot0.value) plot0.index_mapper = index_mapper index_mapper.range.add(plot0.index) if batch.isSelected: Container.add(plot0) index = index + 1 self.RightPlot = Container
def _get_plot_multiline(self): if self.data is None or len(self.data.shape) == 1: return numpoints = self.data.shape[1] if self.scale_type == 'Time': index_x = self._create_dates(numpoints, start=self.first_day) else: index_x = np.arange(numpoints) index_y = np.linspace(1, self.data.shape[0], self.data.shape[0]) xs = ArrayDataSource(index_x) xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(index_y) yrange = DataRange1D() yrange.add(ys) # The data source for the MultiLinePlot. ds = MultiArrayDataSource(data=self.data) corr_plot = \ MultiLinePlot( index=xs, yindex=ys, index_mapper=LinearMapper(range=xrange), value_mapper=LinearMapper(range=yrange), value=ds, global_max=self.data.max(), global_min=self.data.min()) corr_plot.value_mapper.range.low = 0 corr_plot.value_mapper.range.high = self.data.shape[0] + 1 self.multi_line_plot_renderer = corr_plot plot = Plot(title=self.p_title) if self.scale_type == 'Time': # Just the last axis shows tick_labels bottom_axis = PlotAxis(component=plot, orientation="bottom", title=self.x_lbl, tick_generator=ScalesTickGenerator( scale=CalendarScaleSystem())) else: bottom_axis = PlotAxis(orientation='bottom', title=self.x_lbl, title_font="modern 12", tick_visible=True, small_axis_style=True, axis_line_visible=False, component=plot) if self.y_lbl_type == 'Custom' and \ len(self.y_labels) == self.data.shape[0]: # a new value in the list defaults to None so raise an error before # the operator ends inputing it. left_axis = LabelAxis(component=plot, orientation='left', title=self.x_lbl, mapper=corr_plot.value_mapper, tick_interval=1.0, labels=self.y_labels, positions=index_y) else: left_axis = PlotAxis( component=plot, orientation='left', title=self.y_lbl, title_font="modern 12", #title_spacing=0, tick_label_font="modern 8", tick_visible=True, small_axis_style=True, axis_line_visible=False, ensure_labels_bounded=True, #tick_label_color="transparent", mapper=corr_plot.value_mapper) plot.overlays.extend([bottom_axis, left_axis]) plot.add(corr_plot) plot.padding_bottom = 50 return plot
def _get_plot_multiline(self): if self.data is None or len(self.data.shape) == 1: return numpoints = self.data.shape[1] if self.scale_type == 'Time': index_x = self._create_dates(numpoints, start=self.first_day) else: index_x = np.arange(numpoints) index_y = np.linspace(1, self.data.shape[0], self.data.shape[0]) xs = ArrayDataSource(index_x) xrange = DataRange1D() xrange.add(xs) ys = ArrayDataSource(index_y) yrange = DataRange1D() yrange.add(ys) # The data source for the MultiLinePlot. ds = MultiArrayDataSource(data=self.data) corr_plot = \ MultiLinePlot( index=xs, yindex=ys, index_mapper=LinearMapper(range=xrange), value_mapper=LinearMapper(range=yrange), value=ds, global_max=self.data.max(), global_min=self.data.min()) corr_plot.value_mapper.range.low = 0 corr_plot.value_mapper.range.high = self.data.shape[0] + 1 self.multi_line_plot_renderer = corr_plot plot = Plot(title=self.p_title) if self.scale_type == 'Time': # Just the last axis shows tick_labels bottom_axis = PlotAxis(component=plot, orientation="bottom", title=self.x_lbl, tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem())) else: bottom_axis = PlotAxis(orientation='bottom', title=self.x_lbl, title_font="modern 12", tick_visible=True, small_axis_style=True, axis_line_visible=False, component=plot) if self.y_lbl_type == 'Custom' and \ len(self.y_labels) == self.data.shape[0]: # a new value in the list defaults to None so raise an error before # the operator ends inputing it. left_axis = LabelAxis(component=plot, orientation='left', title=self.x_lbl, mapper=corr_plot.value_mapper, tick_interval=1.0, labels=self.y_labels, positions=index_y) else: left_axis = PlotAxis(component=plot, orientation='left', title=self.y_lbl, title_font="modern 12", #title_spacing=0, tick_label_font="modern 8", tick_visible=True, small_axis_style=True, axis_line_visible=False, ensure_labels_bounded=True, #tick_label_color="transparent", mapper=corr_plot.value_mapper) plot.overlays.extend([bottom_axis, left_axis]) plot.add(corr_plot) plot.padding_bottom = 50 return plot