def _create_plot_component(): # Create a random scattering of XY pairs x = random.uniform(0.0, 10.0, 50) y = random.uniform(0.0, 5.0, 50) pd = ArrayPlotData(x=x, y=y) plot = Plot(pd, border_visible=True, overlay_border=True) scatter = plot.plot(("x", "y"), type="scatter", color="lightblue")[0] # Tweak some of the plot properties plot.set(title="Scatter Inspector Demo", padding=50) # Attach some tools to the plot plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) # Attach the inspector and its overlay scatter.tools.append(ScatterInspector(scatter)) overlay = ScatterInspectorOverlay( scatter, hover_color="red", hover_marker_size=6, selection_marker_size=6, selection_color="yellow", selection_outline_color="purple", selection_line_width=3, ) scatter.overlays.append(overlay) return plot
def _plot_default(self): # Create a GridContainer to hold all of our plots: 2 rows, 3 columns container = GridPlotContainer(shape=(2,3), spacing=(10,5), valign='top', bgcolor='lightgray') # Create x data x = linspace(-5, 15.0, 100) pd = ArrayPlotData(index = x) # Plot some Bessel functions and add the plots to our container for i in range(6): data_name = 'y{}'.format(i) pd.set_data(data_name, jn(i,x)) plot = Plot(pd) plot.plot(('index', data_name), color=COLOR_PALETTE[i], line_width=3.0) # Set each plot's aspect based on its position in the grid plot.set(height=((i % 3) + 1)*50, resizable='h') # Add to the grid container container.add(plot) return container
def _create_plot_component(): # Create a random scattering of XY pairs x = random.uniform(0.0, 10.0, 50) y = random.uniform(0.0, 5.0, 50) pd = ArrayPlotData(x=x, y=y) plot = Plot(pd, border_visible=True, overlay_border=True) scatter = plot.plot(("x", "y"), type="scatter", color="lightblue")[0] # Tweak some of the plot properties plot.set(title="Scatter Inspector Demo", padding=50) # Attach some tools to the plot plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) # Attach the inspector and its overlay scatter.tools.append(ScatterInspector(scatter)) overlay = ScatterInspectorOverlay(scatter, hover_color="red", hover_marker_size=6, selection_marker_size=6, selection_color="yellow", selection_outline_color="purple", selection_line_width=3) scatter.overlays.append(overlay) return plot
def _plot_default(self): # Create data x = linspace(-5, 15.0, 100) y = jn(3, x) pd = ArrayPlotData(index=x, value=y) zoomable_plot = Plot(pd) zoomable_plot.plot(('index', 'value'), name='external', color='red', line_width=3) # Attach tools to the plot zoom = ZoomTool(component=zoomable_plot, tool_mode="box", always_on=False) zoomable_plot.overlays.append(zoom) zoomable_plot.tools.append(PanTool(zoomable_plot)) # Create a second inset plot, not resizable, not zoom-able inset_plot = Plot(pd) inset_plot.plot(('index', 'value'), color='blue') inset_plot.set(resizable='', bounds=[250, 150], position=[450, 350], border_visible=True) # Create a container and add our plots container = OverlayPlotContainer() container.add(zoomable_plot) container.add(inset_plot) return container
def _create_plot_component(): # Create a random scattering of XY pairs x = random.uniform(0.0, 10.0, 50) y = random.uniform(0.0, 5.0, 50) pd = ArrayPlotData(x = x, y = y) plot = Plot(pd, border_visible=True, overlay_border=True) scatter = plot.plot(("x", "y"), type="scatter", color="lightblue")[0] # Tweak some of the plot properties plot.set(title="Scatter Inspector Demo", padding=50) # Attach some tools to the plot plot.tools.append(PanTool(plot)) plot.overlays.append(ZoomTool(plot)) # Attach the inspector and its overlay inspector = ScatterInspector(scatter) scatter.tools.append(inspector) overlay = ScatterInspectorOverlay(scatter, hover_color="red", hover_marker_size=6, selection_marker_size=6, selection_color="yellow", selection_outline_color="purple", selection_line_width=3) scatter.overlays.append(overlay) # Optional: add a listener on inspector events: def echo(new): print("{} event on element {}".format(new.event_type, new.event_index)) inspector.on_trait_change(echo, "inspector_event") return plot
def _create_plot_component(): # Create some x-y data series to plot x = linspace(-2.0, 10.0, 100) pd = ArrayPlotData(index = x) for i in range(5): pd.set_data("y" + str(i), jn(i,x)) # Create some line plots of some of the data plot1 = Plot(pd) plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot1.plot(("index", "y3"), name="j_3", color="blue") # Tweak some of the plot properties plot1.title = "Inset Plot" plot1.padding = 50 # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) plot1.overlays.append(zoom) # Create a second scatter plot of one of the datasets, linking its # range to the first plot plot2 = Plot(pd, range2d=plot1.range2d, padding=50) plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle") plot2.set(resizable = "", bounds = [250, 250], position = [550,150], bgcolor = "white", border_visible = True, unified_draw = True ) plot2.tools.append(PanTool(plot2)) plot2.tools.append(MoveTool(plot2, drag_button="right")) zoom = ZoomTool(component=plot2, tool_mode="box", always_on=False) plot2.overlays.append(zoom) # Create a container and add our plots container = OverlayPlotContainer() container.add(plot1) container.add(plot2) return container
def _plot_default(self): # Create data x = linspace(-5, 15.0, 100) y = jn(3, x) pd = ArrayPlotData(index=x, value=y) zoomable_plot = Plot(pd) zoomable_plot.plot(("index", "value"), name="external", color="red", line_width=3) # Attach tools to the plot zoom = ZoomTool(component=zoomable_plot, tool_mode="box", always_on=False) zoomable_plot.overlays.append(zoom) zoomable_plot.tools.append(PanTool(zoomable_plot)) # Create a second inset plot, not resizable, not zoom-able inset_plot = Plot(pd) inset_plot.plot(("index", "value"), color="blue") inset_plot.set(resizable="", bounds=[250, 150], position=[450, 350], border_visible=True) # Create a container and add our plots container = OverlayPlotContainer() container.add(zoomable_plot) container.add(inset_plot) return container