def draw_colorbar(self): scatplot=self.scatplot cmap_renderer = scatplot.plots["my_plot"][0] selection = ColormappedSelectionOverlay(cmap_renderer, fade_alpha=0.35, selection_type="range") cmap_renderer.overlays.append(selection) if self.thresh is not None: cmap_renderer.color_data.metadata['selections']=self.thresh cmap_renderer.color_data.metadata_changed={'selections':self.thresh} # Create the colorbar, handing in the appropriate range and colormap colormap=scatplot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=DataRange1D(low = 0.0, high = 1.0)), orientation='v', resizable='v', width=30, padding=20) colorbar_selection=RangeSelection(component=colorbar) colorbar.tools.append(colorbar_selection) ovr=colorbar.overlays.append(RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray", metadata_name='selections')) #ipshell('colorbar, colorbar_selection and ovr available:') self.cbar_selection=colorbar_selection self.cmap_renderer=cmap_renderer colorbar.plot = cmap_renderer colorbar.padding_top = scatplot.padding_top colorbar.padding_bottom = scatplot.padding_bottom self.colorbar=colorbar return colorbar
def create_colorbar(plt): colormap = plt.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', width=30, padding=20) colorbar.plot = plt return colorbar
def _create_plot_component(): # Create some data numpts = 1000 x = sort(random(numpts)) y = random(numpts) color = exp(-(x**2 + y**2)) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) pd.set_data("color", color) # Create the plot plot = Plot(pd) plot.plot(("index", "value", "color"), type="cmap_scatter", name="my_plot", color_mapper=gist_earth, marker="square", fill_alpha=0.5, marker_size=8, outline_color="black", border_visible=True, bgcolor="white") # Tweak some of the plot properties plot.title = "Colormapped Scatter Plot with Pan/Zoom Color Bar" plot.padding = 50 plot.x_grid.visible = False plot.y_grid.visible = False plot.x_axis.font = "modern 16" plot.y_axis.font = "modern 16" # Add pan and zoom to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(plot) plot.overlays.append(zoom) # Create the colorbar, handing in the appropriate range and colormap colorbar = ColorBar( index_mapper=LinearMapper(range=plot.color_mapper.range), color_mapper=plot.color_mapper, orientation='v', resizable='v', width=30, padding=20) colorbar.plot = plot colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # Add pan and zoom tools to the colorbar colorbar.tools.append( PanTool(colorbar, constrain_direction="y", constrain=True)) zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range", always_on=True, drag_button="right") colorbar.overlays.append(zoom_overlay) # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(plot, colorbar, use_backbuffer=True, bgcolor="lightgray") return container
def create_plot_component(self):# Create a scalar field to colormap # Create the plot self.pd = ArrayPlotData() self.pd.set_data("imagedata", self.fxydata()) plot = Plot(self.pd) cmap = default_colormaps.color_map_name_dict[self.colormap] if self.rev_cmap: cmap = default_colormaps.reverse(cmap) img_plot = plot.img_plot("imagedata", xbounds = self.xbounds, ybounds = self.ybounds, colormap=cmap, )[0] # Tweak some of the plot properties plot.title = self.title plot.padding = 50 # Attach some tools to the plot #plot.tools.append(PanTool(plot)) #zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) #plot.overlays.append(zoom) csr = CursorTool(img_plot, drag_button='left', color='white', line_width=2.0 ) self.cursor = csr csr.current_position = np.mean(self.xbounds), np.mean(self.ybounds) img_plot.overlays.append(csr) imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool, bgcolor="white", border_visible=True,) #img_plot.overlays.append(overlay) colorbar = ColorBar(index_mapper=LinearMapper(range=plot.color_mapper.range), color_mapper=plot.color_mapper, orientation='v', resizable='v', width=30, padding=20) colorbar.plot = plot colorbar.padding_top = plot.padding_top + 10 colorbar.padding_bottom = plot.padding_bottom # Add pan and zoom tools to the colorbar colorbar.tools.append(PanTool(colorbar, constrain_direction="y", constrain=True)) zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range", always_on=True, drag_button="right") colorbar.overlays.append(zoom_overlay) # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(plot, colorbar, use_backbuffer=True, bgcolor="transparent",) container.overlays.append(overlay) #self.plot = plot self.plot = container
def _create_plot_component(): # Create some data numpts = 500 x1 = random(numpts) y1 = random(numpts) x2 = x1 + standard_normal(numpts) * 0.05 y2 = y1 + standard_normal(numpts) * 0.05 color = exp(-(x1**2 + y2**2)) widths = random(numpts) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", column_stack([x1, x2]).reshape(-1)) pd.set_data("value", column_stack([y1, y2]).reshape(-1)) pd.set_data("color", color) pd.set_data("widths", widths) # Create the plot plot = Plot(pd) plot.plot(("index", "value", "color", "widths"), type="cmap_segment", name="my_plot", color_mapper=viridis, border_visible=True, render_style='cubic', bgcolor="white", size_min=0.5, size_max=5.0) # Tweak some of the plot properties plot.title = "Colormapped Segment Plot with variable widths" plot.padding = 50 plot.x_grid.visible = False plot.y_grid.visible = False plot.x_axis.font = "modern 16" plot.y_axis.font = "modern 16" # Right now, some of the tools are a little invasive, and we need the # actual ColomappedSegmentPlot object to give to them cmap_renderer = plot.plots["my_plot"][0] # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Create the colorbar, handing in the appropriate range and colormap colorbar = ColorBar( index_mapper=LinearMapper(range=plot.color_mapper.range), color_mapper=plot.color_mapper, orientation='v', resizable='v', width=30, padding=20) colorbar.plot = cmap_renderer colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(use_backbuffer=True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" return container
def _create_plot_component(): # Create some data numpts = 1000 x = sort(random(numpts)) y = random(numpts) color = exp(-(x**2 + y**2)) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) pd.set_data("color", color) # Create the plot plot = Plot(pd) plot.plot(("index", "value", "color"), type="cmap_scatter", name="my_plot", color_mapper=gist_earth, marker = "square", fill_alpha = 0.5, marker_size = 8, outline_color = "black", border_visible = True, bgcolor = "white") # Tweak some of the plot properties plot.title = "Colormapped Scatter Plot with Pan/Zoom Color Bar" plot.padding = 50 plot.x_grid.visible = False plot.y_grid.visible = False plot.x_axis.font = "modern 16" plot.y_axis.font = "modern 16" # Add pan and zoom to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(plot) plot.overlays.append(zoom) # Create the colorbar, handing in the appropriate range and colormap colorbar = ColorBar(index_mapper=LinearMapper(range=plot.color_mapper.range), color_mapper=plot.color_mapper, orientation='v', resizable='v', width=30, padding=20) colorbar.plot = plot colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # Add pan and zoom tools to the colorbar colorbar.tools.append(PanTool(colorbar, constrain_direction="y", constrain=True)) zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range", always_on=True, drag_button="right") colorbar.overlays.append(zoom_overlay) # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(plot, colorbar, use_backbuffer=True, bgcolor="lightgray") return container