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 _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 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_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