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 __init__(self, link): super(TrackingView, self).__init__() self.n_channels = None self.plot_data = ArrayPlotData(t=[0.0]) self.plot = Plot(self.plot_data, auto_colors=colours_list, emphasized=True) self.plot.title = 'Tracking C/N0' self.plot.title_color = [0, 0, 0.43] self.plot.value_range.margin = 0.1 self.plot.value_range.bounds_func = lambda l, h, m, tb: (0, h * (1 + m)) self.plot.value_axis.orientation = 'right' self.plot.value_axis.axis_line_visible = False self.plot.value_axis.title = 'dB-Hz' t = range(NUM_POINTS) self.plot_data.set_data('t', t) self.plot.legend.visible = True self.plot.legend.align = 'ul' self.plot.legend.tools.append( LegendTool(self.plot.legend, drag_button="right")) self.link = link self.link.add_callback(self.tracking_state_callback, SBP_MSG_TRACKING_STATE) self.python_console_cmds = {'track': self}
def __init__(self): super(TrackingView, self).__init__() self.first = False self.counter = 0 self.t_init = time.time() self.time = [x * 1 / TRK_RATE for x in range(-NUM_POINTS, 0, 1)] self.CN0_dict = defaultdict(lambda: np.zeros(NUM_POINTS)) self.glo_slot_dict = {} self.n_channels = None self.plot_data = ArrayPlotData(t=[0.0]) self.plot = Plot(self.plot_data, emphasized=True) self.plot.title = 'Tracking C/N0' self.plot.title_color = [0, 0, 0.43] self.ylim = self.plot.value_mapper.range self.ylim.low = SNR_THRESHOLD self.ylim.high = 60 self.plot.value_range.bounds_func = lambda l, h, m, tb: (0, h * (1 + m)) self.plot.value_axis.orientation = 'right' self.plot.value_axis.axis_line_visible = False self.plot.value_axis.title = 'dB-Hz' self.plot_data.set_data('t', self.time) self.plot.index_axis.title = 'seconds' self.plot.index_range.bounds_func = lambda l, h, m, tb: (h - 100, h) self.legend_visible = True self.plot.legend.visible = True self.plot.legend.align = 'll' self.plot.legend.line_spacing = 1 self.plot.legend.font = 'monospace 8' self.plot.legend.draw_layer = 'overlay' self.plot.legend.tools.append( LegendTool(self.plot.legend, drag_button="right"))
def __init__(self, link): super(TrackingView, self).__init__() self.t_init = time.time() self.time = [x * 1/TRK_RATE for x in range(-NUM_POINTS, 0, 1)] self.CN0_dict = {} self.n_channels = None self.plot_data = ArrayPlotData(t=[0.0]) self.plot = Plot(self.plot_data, emphasized=True) self.plot.title = 'Tracking C/N0' self.plot.title_color = [0, 0, 0.43] self.ylim = self.plot.value_mapper.range self.ylim.low = SNR_THRESHOLD self.ylim.high = 60 self.plot.value_range.bounds_func = lambda l, h, m, tb: (0, h * (1 + m)) self.plot.value_axis.orientation = 'right' self.plot.value_axis.axis_line_visible = False self.plot.value_axis.title = 'dB-Hz' self.plot_data.set_data('t', self.time) self.plot.index_axis.title = 'seconds' self.plot.index_range.bounds_func = lambda l, h, m, tb: (h - 100, h) self.legend_visible = True self.show_l1 = True self.show_l2 = True self.plot.legend.visible = True self.plot.legend.align = 'll' self.plot.legend.line_spacing = 1 self.plot.legend.font = 'modern 8' self.plot.legend.draw_layer= 'overlay' self.plot.legend.tools.append(LegendTool(self.plot.legend, drag_button="right")) self.link = link self.link.add_callback(self.tracking_state_callback, SBP_MSG_TRACKING_STATE) self.python_console_cmds = { 'track': self }
def add_tools(self, plot): """ Add all tools specified in plot_tools list to provided plot. """ broadcaster = BroadcasterTool() # IMPORTANT: add the broadcast tool to one of the renderers, NOT the # container. Otherwise, the box zoom will crop wrong: first_plot = plot.components[0] first_plot.tools.append(broadcaster) for i, plot in enumerate(plot.components): if "pan" in self.plot_tools: pan = PanTool(plot) broadcaster.tools.append(pan) if "zoom" in self.plot_tools: # FIXME: the zoom tool is added to the broadcaster's tools # attribute because it doesn't have an overlay list. That # means the box plot mode won't display the blue box! zoom = ZoomTool(component=plot, zoom_factor=1.15) broadcaster.tools.append(zoom) if "legend" in self.plot_tools and self.legend: legend = self.legend legend.tools.append( LegendTool(component=self.legend, drag_button="right")) legend.tools.append(LegendHighlighter(component=legend)) if "context_menu" in self.plot_tools: self.context_menu_manager.target = self.plot menu = self.context_menu_manager.build_menu() context_menu = ContextMenuTool(component=self.plot, menu_manager=menu) self.plot.tools.append(context_menu)
def _legend_visible_changed(self): if self.plot: if not self.legend_visible: self.plot.legend.visible = False else: self.plot.legend.visible = True self.plot.legend.tools.append( LegendTool(self.plot.legend, drag_button="right"))
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, link): super(VelocityView, self).__init__() self.velocity_units = 'm/s' self.vel_sf = 1.0 self.v_h = np.zeros(NUM_POINTS) self.v_z = np.zeros(NUM_POINTS) self.t = np.zeros(NUM_POINTS) self.last_plot_update_time = 0 self.plot_data = ArrayPlotData(t=np.arange(NUM_POINTS), v_h=[0.0], v_z=[0.0]) self.plot = Plot(self.plot_data, auto_colors=colors_list, emphasized=True) self.plot.title_color = [0, 0, 0.43] self.plot.value_axis.orientation = 'right' self.plot.value_axis.axis_line_visible = False self.plot.value_axis.title = 'm/s' self.plot.value_axis.font = 'modern 8' self.plot.index_axis.title = 'GPS Time of Week' self.plot.index_axis.title_spacing = 40 self.plot.index_axis.tick_label_font = 'modern 8' self.plot.value_axis.tick_color = 'gray' self.plot.index_axis.tick_label_rotate_angle = -45 self.plot.title_visible = False self.legend_visible = True self.plot.legend.visible = True self.plot.legend.align = 'll' self.plot.legend.line_spacing = 1 self.plot.legend.font = 'modern 8' self.plot.legend.draw_layer = 'overlay' self.plot.legend.tools.append( LegendTool(self.plot.legend, drag_button="right")) self.plot.padding_left = 35 self.plot.padding_bottom = 60 self.plot_paddint_top = -1 self.plot.padding_right = 60 vel_h = self.plot.plot(('t', 'v_h'), type='line', color='auto', name='Horizontal') vel_v = self.plot.plot(('t', 'v_z'), type='line', color='auto', name='Vertical') self.link = link self.link.add_callback(self.vel_ned_callback, SBP_MSG_VEL_NED) self.python_console_cmds = {'vel': self} self.update_scheduler = UpdateScheduler()
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 __init__(self, link): super(IMUView, self).__init__() self.acc = np.zeros((NUM_POINTS, 3)) self.gyro = np.zeros((NUM_POINTS, 3)) self.plot_data = ArrayPlotData( t=np.arange(NUM_POINTS), acc_x=[0.0], acc_y=[0.0], acc_z=[0.0], gyr_x=[0.0], gyr_y=[0.0], gyr_z=[0.0]) self.plot = Plot( self.plot_data, auto_colors=colours_list, emphasized=True) self.plot.title = 'Raw IMU Data' self.plot.title_color = [0, 0, 0.43] self.ylim = self.plot.value_mapper.range self.ylim.low = -32768 self.ylim.high = 32767 # self.plot.value_range.bounds_func = lambda l, h, m, tb: (0, h * (1 + m)) self.plot.value_axis.orientation = 'right' self.plot.value_axis.axis_line_visible = False self.plot.value_axis.title = 'LSB count' call_repeatedly(0.2, self.imu_set_data) self.legend_visible = True self.plot.legend.visible = True self.plot.legend.align = 'll' self.plot.legend.line_spacing = 1 self.plot.legend.font = 'modern 8' self.plot.legend.draw_layer = 'overlay' self.plot.legend.tools.append( LegendTool(self.plot.legend, drag_button="right")) acc_x = self.plot.plot( ('t', 'acc_x'), type='line', color='auto', name='Accn. X') acc_x = self.plot.plot( ('t', 'acc_y'), type='line', color='auto', name='Accn. Y') acc_x = self.plot.plot( ('t', 'acc_z'), type='line', color='auto', name='Accn. Z') acc_x = self.plot.plot( ('t', 'gyr_x'), type='line', color='auto', name='Gyro X') acc_x = self.plot.plot( ('t', 'gyr_y'), type='line', color='auto', name='Gyro Y') acc_x = self.plot.plot( ('t', 'gyr_z'), type='line', color='auto', name='Gyro Z') self.link = link self.link.add_callback(self.imu_raw_callback, SBP_MSG_IMU_RAW) self.link.add_callback(self.imu_aux_callback, SBP_MSG_IMU_AUX) self.python_console_cmds = {'track': self}
def _default_plot(self): plot = Plot(self.pd, padding=50, fill_padding=True, bgcolor="white", use_backbuffer=True, unified_draw=True) plot.tools.append(PanTool(plot, constrain_key="shift")) plot.overlays.append( ZoomTool(component=plot, tool_mode="box", always_on=False)) plot.legend.tools.append(LegendTool(plot.legend, drag_button="right")) return plot
def _default_plot(self): global Plot, PanTool, ZoomTool, LegendTool if Plot==None: from chaco.plot import Plot if PanTool==None or ZoomTool==None or LegendTool==None: from chaco.tools.api import PanTool, ZoomTool, LegendTool #, LineInspector plot=Plot(self.pd, padding=50, fill_padding=True, bgcolor="white", use_backbuffer=True, unified_draw=True)#, use_downsampling=True) plot.tools.append(PanTool(plot, constrain_key="shift")) plot.overlays.append(ZoomTool(component=plot, tool_mode="box", always_on=False)) plot.legend.tools.append(LegendTool(plot.legend, drag_button="right")) return plot
def __init__(self, link): super(MagView, self).__init__() self.mag = np.zeros((NUM_POINTS, 3)) self.plot_data = ArrayPlotData(t=np.arange(NUM_POINTS), mag_x=[0.0], mag_y=[0.0], mag_z=[0.0]) self.plot = Plot(self.plot_data, auto_colors=colours_list, emphasized=True) self.plot.title = 'Raw Magnetometer Data' self.plot.title_color = [0, 0, 0.43] self.plot.value_axis.orientation = 'right' self.plot.value_axis.axis_line_visible = False call_repeatedly(0.2, self.mag_set_data) self.legend_visible = True self.plot.legend.visible = True self.plot.legend.align = 'll' self.plot.legend.line_spacing = 1 self.plot.legend.font = 'modern 8' self.plot.legend.draw_layer = 'overlay' self.plot.legend.tools.append( LegendTool(self.plot.legend, drag_button="right")) mag_x = self.plot.plot(('t', 'mag_x'), type='line', color='auto', name='Mag. X (uT)') mag_y = self.plot.plot(('t', 'mag_y'), type='line', color='auto', name='Mag. Y (uT)') mag_z = self.plot.plot(('t', 'mag_z'), type='line', color='auto', name='Mag. Z (uT)') self.link = link self.link.add_callback(self.mag_raw_callback, SBP_MSG_MAG_RAW) self.python_console_cmds = {'track': self}
def __init__(self, link, legend_visible=True): super(TrackingView, self).__init__() self._at_least_one_track_received = False self.t_init = monotonic() self.time = deque([x * 1 / TRK_RATE for x in range(-NUM_POINTS, 0, 1)], maxlen=NUM_POINTS) self.CN0_lock = threading.Lock() self.CN0_dict = defaultdict( lambda: deque([0] * NUM_POINTS, maxlen=NUM_POINTS)) self.CN0_age = defaultdict(lambda: -1) self.sv_labels = [] self.glo_fcn_dict = {} self.glo_slot_dict = {} self.n_channels = None self.plot_data = ArrayPlotData(t=[0.0]) self.plot = Plot(self.plot_data, emphasized=True) self.plot.title = 'Tracking C/N0' self.plot.title_color = [0, 0, 0.43] self.ylim = self.plot.value_mapper.range self.ylim.low = SNR_THRESHOLD self.ylim.high = 60 self.plot.value_range.bounds_func = lambda l, h, m, tb: (0, h * (1 + m)) self.plot.value_axis.orientation = 'right' self.plot.value_axis.axis_line_visible = False self.plot.value_axis.title = 'dB-Hz' self.plot_data.set_data('t', self.time) self.plot.index_axis.title = 'seconds' self.legend_visible = True self.plot.legend.visible = legend_visible self.plot.legend.align = 'll' self.plot.legend.line_spacing = 1 self.plot.legend.font = 'monospace 8' self.plot.legend.draw_layer = 'overlay' self.plot.legend.tools.append( LegendTool(self.plot.legend, drag_button="right")) self.link = link self.link.add_callback(self.measurement_state_callback, SBP_MSG_MEASUREMENT_STATE) self.link.add_callback(self.tracking_state_callback, SBP_MSG_TRACKING_STATE) self.python_console_cmds = {'track': self} self.update_scheduler = UpdateScheduler()
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_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=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 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 drag_end(self, event): if hasattr(event, "bid"): event.window.release_blob(event.bid) self.event_state = "normal" LegendTool.drag_end(self, event)
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