def _tt1_fired(self): self.addele() self.plotdata.del_data("x") self.plotdata.del_data("y") self.plotdata.del_data("xrt") self.plotdata.del_data("xx") self.plotdata.del_data("yy") self.plotdata.del_data("tt") self.plotdata.set_data("x",self.x) self.plotdata.set_data("y",self.y) self.plotdata.set_data("xrt",self.xrt) self.plotdata.set_data("xx",xx) self.plotdata.set_data("yy",yy) self.plotdata.set_data("tt",self.ttt) plot1 = Plot(self.plotdata) plot1.plot(("x", "y"),type="line",color="blue",name='1') plot1.plot(("x", "y"),type="scatter",color="blue", marker = 'circle', marker_size = 2,name='1') plot1.plot(("x", "xrt"),type="line",color="red",name='2') plot1.plot(("x", "xrt"),type="scatter",color="red", marker = 'circle', marker_size = 2,name='2') plot2 = Plot(self.plotdata) plot2.plot(("xx", "yy"),type="line",color="blue") plot2.plot(("xx","yy"),type="scatter",color="blue") plot3 = Plot(self.plotdata) plot3.plot(("x", "tt"),type="line",color="blue") plot3.plot(("x","tt"),type="scatter",color="blue") container = HPlotContainer(plot1,plot2,plot3) self.plot= container legend= Legend(padding=10, align="ur") legend.plots = plot1.plots plot1.overlays.append(legend)
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 _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_angle_names_changed(self): for _myos_in in range(2): self.stream_Angle[_myos_in] = 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 _select_emg_names_changed(self): for chanel in range(8): self.stream_emg[chanel] = 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 _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 _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 _plots_default(self): plotdata = self.get_data_sets() plots = Plot(plotdata) plotsDict = {} # plot background sonar image and impound lines xbounds = self.model.survey_rng_m ybounds = self.model.depth_m plots.img_plot("sonarimg", colormap=jet, xbounds=xbounds, ybounds=ybounds) ip = plots.plot(('impound1_X','impound1_Y'), type='line', marker='square') plotsDict['Impoundment line'] = ip plots.x_axis.title = 'Distance along survey line (m)' plots.y_axis.title = 'Depth (m)' # add core samples as scatter with separate y-axis corex = plotdata.get_data('coreX') corey = plotdata.get_data('coreY') scatter = create_scatter_plot((corex,corey), marker='diamond', color='red' ) scatter.index_range = plots.index_range axis = PlotAxis(scatter, orientation='right') axis.title = 'Core sample dist from survey line (m)' scatter.underlays.append(axis) plots.add(scatter) # create vertical line for indicating selected core sample position vals1 = [0 for x in corey] vline = create_line_plot((corey,vals1), color='blue', orientation='v') vline.value_range = scatter.index_range plots.add(vline) # Add Legend legend = Legend(component=plots, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="left")) legend.plots = plotsDict plots.overlays.append(legend) # Add tools scatter.tools.append(PickTool(scatter)) plots.tools.append(TraceTool(plots)) plots.tools.append(PanTool(plots)) plots.tools.append(ZoomTool(plots)) return plots
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 __init__(self): super(calc, self).__init__() self.addele() self.plotdata = ArrayPlotData(x = self.x, y = self.y, xrt=self.xrt, xx=xx, yy=yy,tt=self.ttt) plot1 = Plot(self.plotdata) plot1.plot(("x", "y"),type="line",color="blue",name='1') plot1.plot(("x", "y"),type="scatter",color="blue", marker = 'circle', marker_size = 2,name='1') plot1.plot(("x", "xrt"),type="line",color="red",name='2') plot1.plot(("x", "xrt"),type="scatter",color="red", marker = 'circle', marker_size = 2,name='2') plot2 = Plot(self.plotdata) plot2.plot(("xx", "yy"),type="line",color="blue") plot2.plot(("xx","yy"),type="scatter",color="blue") plot3 = Plot(self.plotdata) plot3.plot(("x", "tt"),type="line",color="blue") plot3.plot(("x","tt"),type="scatter",color="blue") container = HPlotContainer(plot1,plot2,plot3) self.plot= container legend= Legend(padding=10, align="ur") legend.plots = plot1.plots plot1.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 _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 _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=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
def build_plot(self): global plotdata # FIXME: Don't use global! 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'] self.y = {} for comp in self.CompoList: self.y[comp] = stats.norm.pdf( self.mod_x, self.Components[comp][0] + self.line_center, self.Components[comp][1] ) * self.Components[comp][1] * sp.sqrt(2. * sp.pi) * \ 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 - 20) & (self.x < self.line_center + 20)) # Define the y axis max value in initial view (can be panned/zoomed): maxval = float(self.indata[plotrange].max() * 1.1) minval = maxval / 15. maxerr = self.errs[plotrange].max() * 1.3 resmin = max(self.Resids[plotrange].max(), 5.) * 1.2 cenx = sp.array([self.line_center, self.line_center]) ceny = sp.array([-minval, maxval]) cenz = sp.array([-maxval, maxval]) # Build plot of data and model 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, ) for comp in self.CompoList: plotdata.set_data(comp, self.y[comp]) olplot = GridContainer(shape=(2, 1), padding=10, fill_padding=True, bgcolor='transparent', spacing=(5, 10)) plot = Plot(plotdata) plot.y_axis.title = 'Flux density' resplot = Plot(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.) # There may be an arbitrary number of gaussian components, so: for comp in self.CompoList: self.comprenders.append( plot.plot(('xs', comp), type='line', #color='auto', color=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) 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 - 20., self.line_center + 20.) 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=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 _create_plot_component(): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) fprefix = './test_data/CEN184/' filename1 = fprefix + 'THL_2012-03-21_18-40-42_000.dat' filename2 = fprefix + 'THL_2012-03-21_18-44-42_000.dat' fprefix = './test_data/CEN111/' filename3 = fprefix + 'THL_2011-07-09_15-02-54_000.dat' ioreader = HekaIO(filename3) #read a block blo = ioreader.read_block(group = 2) #protocol stuff f = open(filename1) head = BundleHeader(f) head.load(f) bi = head.oBundleItems[2] pgf = PGFFile(f,bi) value_mapper = None index_mapper = None plots = {} firstplot = True for seg in blo.segments: #prococol building for a_sig in seg.analogsignals: x = array(a_sig.times) y = array(a_sig) ch = int(a_sig.annotations['trSourceChannel']) plot = create_line_plot((x,y), width=0.5,color=tuple(COLOR_PALETTE[ch])) plot.index.sort_order = "ascending" plot.bgcolor = "white" plot.border_visible = True #code for protocols print "###########################" st_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['contents'] se_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['children'][0]['children'][1]['contents'] for key in ['stMark','stDataStartSegment','stDataStartTime']: print key+ ' ' +str(st_rec.__dict__[key]) for key in ['seVoltageIncMode','seDuration','seDurationIncMode','seVoltage',]: print key+' '+str(se_rec.__dict__[key]) for key in ['pgf_index','trTraceCount','trAdcChannel','trSourceChannel','swStimCount']: print "%s:%s"%(key,a_sig.annotations[key]) #se_index = int(seg.annotations['seSeriesCount']) -1 #sw_index = int(a_sig.annotations['swSweepCount']) -1 #st_index = int(a_sig.annotations['swStimCount']) -1 #print pgf.tree['children'][se_index]['children'][st_index]['children'][1]['contents'].seVoltage if not firstplot: plot.value_mapper = value_mapper value_mapper.range.add(plot.value) plot.index_mapper = index_mapper index_mapper.range.add(plot.index) else: value_mapper = plot.value_mapper index_mapper = plot.index_mapper add_default_grids(plot) add_default_axes(plot) plot.index_range.tight_bounds = False plot.index_range.refresh() plot.value_range.tight_bounds = False plot.value_range.refresh() 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")) #print a_sig.annotations plot.overlays.append(legend) firstplot = False container.add(plot) plots["sweep %s"%a_sig.annotations['trLabel'][:4]] = plot # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append(PlotLabel(blo.annotations['grLabel'], component=container, font = "swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container
def __init__(self, **traits): Ice.Application.__init__(self) HasTraits.__init__(self,**traits) plots = {} container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) self.jtrig = 0 # Plot all telescopes self.LSTdefault = ArrayPlotData() self.LSTdefault.set_data('xtel', LSTelX) self.LSTdefault.set_data('ytel', LSTelY) self.plotLST = Plot(self.LSTdefault) self.rLST = self.plotLST.plot(('xtel', 'ytel'), type = "scatter", color = 'black', name = 'LST', marker = 'circle') self.rLST[0].marker_size = 6 self.plotLST.range2d.x_range.high = np.max(TelX + 100.) self.plotLST.range2d.x_range.low = np.min(TelX - 100.) self.plotLST.range2d.y_range.high = np.max(TelY + 100.) self.plotLST.range2d.y_range.low = np.min(TelY - 100.) self.plotLST.title = "Triggered telescopes" container.add(self.plotLST) self.MSTdefault = ArrayPlotData() self.MSTdefault.set_data('xtel', MSTelX) self.MSTdefault.set_data('ytel', MSTelY) self.plotMST = Plot(self.MSTdefault) self.rMST = self.plotMST.plot(('xtel', 'ytel'), type = "scatter", color = 'black', name = 'MST', marker = 'circle') self.rMST[0].marker_size = 4 self.plotMST.range2d = self.plotLST.range2d container.add(self.plotMST) self.SSTdefault = ArrayPlotData() self.SSTdefault.set_data('xtel', SSTelX) self.SSTdefault.set_data('ytel', SSTelY) self.plotSST = Plot(self.SSTdefault) self.rSST = self.plotSST.plot(('xtel', 'ytel'), type = "scatter", color = 'black', name = 'MST', marker = 'circle') self.rSST[0].marker_size = 1 self.plotSST.range2d = self.plotLST.range2d container.add(self.plotSST) self.plotLST.tools.append(PanTool(self.plotLST)) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = ZoomTool(self.plotLST, tool_mode="box", always_on=False) self.plotLST.overlays.append(zoom) # The DragZoom tool just zooms in and out as the user drags # the mouse vertically. dragzoom = DragZoom(self.plotLST, drag_button="right") self.plotLST.tools.append(dragzoom) # Add a legend in the upper right corner, and make it relocatable plots["LST"] = self.rLST plots["MST"] = self.rMST plots["SST"] = self.rSST legend = Legend(component=self.plotLST, padding=10, align="ur", line_spacing = 7, font = 'modern 14') legend.tools.append(LegendTool(legend, drag_button="right")) self.plotLST.overlays.append(legend) legend.plots = plots # Triggered telescopes self.LSTdata = ArrayPlotData() self.LSTdata.set_data('xtel', LSTelX) self.LSTdata.set_data('ytel', LSTelY) self.plotLSTtrig = Plot(self.LSTdata) self.rLSTdata = self.plotLSTtrig.plot(('xtel', 'ytel'), type = "scatter", marker = 'circle', marker_size = 6) self.plotLSTtrig.range2d = self.plotLST.range2d container.add(self.plotLSTtrig) self.MSTdata = ArrayPlotData() self.MSTdata.set_data('xtel', MSTelX) self.MSTdata.set_data('ytel', MSTelY) self.plotMSTtrig = Plot(self.MSTdata) self.rMSTdata = self.plotMSTtrig.plot(('xtel', 'ytel'), type = "scatter", marker = 'circle', marker_size = 4) self.plotMSTtrig.range2d = self.plotMST.range2d container.add(self.plotMSTtrig) self.SSTdata = ArrayPlotData() self.SSTdata.set_data('xtel', SSTelX) self.SSTdata.set_data('ytel', SSTelY) self.plotSSTtrig = Plot(self.SSTdata) self.rSSTdata = self.plotSSTtrig.plot(('xtel', 'ytel'), type = "scatter", marker = 'circle', marker_size = 1) self.plotSSTtrig.range2d = self.plotSST.range2d container.add(self.plotSSTtrig) # Set the list of plots on the legend #legend.plots = plots # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) #draw_png(home_dir + '/Projects/visRTA/Plots/visTrigTel'+str(counter)+'.png', _create_plot_component(self)) #filename = home_dir + '/Projects/visRTA/Plots/visTrigTel'+str(counter)+'.png' #gc = PlotGraphicsContext(size, dpi=72.0) #gc.render_component(container) #gc.save(filename) self.plot = container print "end init"
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()
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 = 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