def _hist2d_default(self): plot = Plot(self.hist2d_data, padding=(20, 0, 0, 40)) plot.img_plot("H", xbounds=self.xedges, ybounds=self.yedges, colormap=jet) plot.index_axis.title = "Voxel dist." plot.value_axis.title = "Root Square Error" # Create a colorbar colormap = plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=20, padding=(20, 30, 0, 0)) 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, padding=0) container.add(colorbar) container.add(plot) container.bgcolor = "lightgray" return container
def _plot_default(self): plot = Plot(self.plotdata) plot.title = "Simplex on the Rosenbrock function" plot.img_plot("background", name="background", xbounds=(0,1.5), ybounds=(0,1.5), colormap=jet(DataRange1D(low=0,high=100)), ) plot.plot(("values_x", "values_y"), type="scatter", color="red") background = plot.plots["background"][0] colormap = background.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=background, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom container = HPlotContainer(use_backbuffer = True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" return container
def control(self): """ A drawable control with a color bar. """ color_map = self.plot_obj.color_mapper linear_mapper = LinearMapper(range=color_map.range) color_bar = ColorBar(index_mapper=linear_mapper, color_mapper=color_map, plot=self.plot_obj, orientation='v', resizable='v', width=30) color_bar._axis.tick_label_formatter = self.sci_formatter color_bar.padding_top = self.padding_top color_bar.padding_bottom = self.padding_bottom color_bar.padding_left = 50 # Room for labels. color_bar.padding_right = 10 range_selection = RangeSelection(component=color_bar) range_selection.listeners.append(self.plot_obj) color_bar.tools.append(range_selection) range_selection_overlay = RangeSelectionOverlay(component=color_bar) color_bar.overlays.append(range_selection_overlay) container = HPlotContainer(use_backbuffer=True) container.add(self) container.add(color_bar) return Window(self.parent, component=container).control
def __init__(self): # Create some data x = np.random.random(N_POINTS) y = np.random.random(N_POINTS) color = np.exp(-(x**2 + y**2)) # Create a plot data object and give it this data data = ArrayPlotData(index=x, value=y, color=color) # Create the plot plot = Plot(data) plot.plot(("index", "value", "color"), type="cmap_scatter", color_mapper=jet) # Create the colorbar, handing in the appropriate range and colormap colormap = plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', width=30, padding=20) 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(plot, colorbar) self.plot = container
def _SmoothPlot_default(self): plotdata = ArrayPlotData(imagedata=self.Smooth) plot = Plot(plotdata, width=500, height=500, resizable='hv') SmoothImage = plot.img_plot( 'imagedata', colormap=gray, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), )[0] SmoothImage.x_mapper.domain_limits = (self.X[0], self.X[-1]) SmoothImage.y_mapper.domain_limits = (self.Y[0], self.Y[-1]) SmoothImage.overlays.append(ZoomTool(SmoothImage)) colormap = SmoothImage.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=10, padding=20) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom self.SmoothImage = SmoothImage container = HPlotContainer(padding=20, fill_padding=True, use_backbuffer=True) container.add(colorbar) container.add(plot) return container
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_colorbar(colormap): colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', width=30, padding=20) colorbar.grid_visible = False colorbar._axis.tick_visible = False colorbar.tools.append(RangeSelection(component=colorbar)) colorbar.overlays.append(RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) return colorbar
def _create_plot_component(model): # Create a plot data object and give it the model's data array. pd = ArrayPlotData() pd.set_data("imagedata", model.data) # Create the "main" Plot. plot = Plot(pd, padding=50) # Use a TransformColorMapper for the color map. tcm = TransformColorMapper.from_color_map(jet) # Create the image plot renderer in the main plot. renderer = plot.img_plot("imagedata", xbounds=model.x_array, ybounds=model.y_array, colormap=tcm)[0] # Create the colorbar. lm = LinearMapper(range=renderer.value_range, domain_limits=(renderer.value_range.low, renderer.value_range.high)) colorbar = ColorBar(index_mapper=lm, plot=plot, orientation='v', resizable='v', width=30, padding=20) 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(use_backbuffer=True) container.add(plot) container.add(colorbar) return container
def _create_plot(self): plot_data = ArrayPlotData(image=self.image) plot = Plot(plot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) plot.img_plot('image', colormap=RdBu_r, xbounds=(self.X[0],self.X[-1]), ybounds=(self.Y[0],self.Y[-1]), name='image') image = plot.plots['image'][0] image.x_mapper.domain_limits = (self.imager.get_x_range()[0],self.imager.get_x_range()[1]) image.y_mapper.domain_limits = (self.imager.get_y_range()[0],self.imager.get_y_range()[1]) zoom = AspectZoomTool(image, enable_wheel=False) cursor = CursorTool2D(image, drag_button='left', color='yellow', marker_size=1.0, line_width=1.0 ) image.overlays.append(cursor) image.overlays.append(zoom) colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(colorbar) z_label = PlotLabel(text='z=0.0', color='red', hjustify='left', vjustify='bottom', position=[10,10]) container.overlays.append(z_label) container.tools.append(SaveTool(container)) self.plot_data = plot_data self.scan_plot = image self.cursor = cursor self.zoom = zoom self.figure = plot self.figure_container = container self.sync_trait('z_label_text', z_label, 'text')
def _figure_image_default(self): plot = Plot(self.plot_data_image, width=180, height=180, padding=3, padding_left=48, padding_bottom=32) plot.img_plot('image', colormap=jet, name='image') plot.aspect_ratio=1 #plot.value_mapper.domain_limits = (scanner.getYRange()[0],scanner.getYRange()[1]) #plot.index_mapper.domain_limits = (scanner.getXRange()[0],scanner.getXRange()[1]) plot.value_mapper.domain_limits = (0,self.size_xy) plot.index_mapper.domain_limits = (0,self.size_xy) container = HPlotContainer() image = plot.plots['image'][0] colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=20, height=200, padding=8, padding_left=20) container = HPlotContainer() container.add(plot) container.add(colorbar) return container
def create_colorbar(colormap): colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', width=30, padding=20) colorbar.grid_visible = False colorbar._axis.tick_visible = False colorbar.tools.append(RangeSelection(component=colorbar)) colorbar.overlays.append( RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) return colorbar
def generate_colorbar(self, desc): """ Generate the colorbar to be displayed along side the main plot. """ plot = desc["plot"] renderer = self._get_cmap_renderer() colormap = renderer.color_mapper # Constant mapper for the color bar so that the colors stay the same # even when data changes colorbar_range = DataRange1D(low=self.plot_style.colorbar_low, high=self.plot_style.colorbar_high) index_mapper = LinearMapper(range=colorbar_range) self.colorbar = ColorBar(index_mapper=index_mapper, color_mapper=colormap, padding_top=plot.padding_top, padding_bottom=plot.padding_bottom, padding_right=40, padding_left=5, resizable='v', orientation='v', width=30) font_size = self.plot_style.color_axis_title_style.font_size font_name = self.plot_style.color_axis_title_style.font_name font = '{} {}'.format(font_name, font_size) axis_kw = dict(title=self.z_axis_title, orientation="right", title_angle=90.0, title_font=font) self.colorbar._axis.trait_set(**axis_kw)
def _color_bar_gen(self, plot, style_dict): """Returns a ColorBar with given style_dict settings Parameters ---------- style_dict: dict dictionary of extra stylings to set, currently allowing up to one level of nesting of attributes (with '' key meaning no nesting) """ renderer = plot.plots["plot0"][0] colormap = renderer.color_mapper style_dict['']['index_mapper'] = LinearMapper(range=colormap.range) style_dict['']['color_mapper'] = colormap style_dict['']['plot'] = renderer kwargs = style_dict.get('') color_bar = ColorBar(**kwargs) # adjust color bar for rest of the attrs for attr_name, attr_styles in style_dict.items(): if attr_name == '': continue attr = getattr(color_bar, attr_name) for attr_attr_name, attr_attr_val in attr_styles.items(): setattr(attr, attr_attr_name, attr_attr_val) return color_bar
def _resplotter_default(self): res = np.zeros((400, 400)) self.pd = ArrayPlotData(res=res) p = Plot(self.pd) img = p.img_plot('res', name="my_plot") my_plot = p.plots["my_plot"][0] colormap = my_plot.color_mapper colorbar = ColorBar( index_mapper=dc.LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', plot=my_plot, resizable='v', width=30, padding=20) range_selection = RangeSelection(component=colorbar) colorbar.tools.append(range_selection) colorbar.overlays.append(RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) range_selection.listeners.append(my_plot) con = HPlotContainer() con.add(p) con.add(colorbar) return con
def make_colorbar(self, plot, width=30, padding=20, orientation='v', resizable='v'): cm = gray(DataRange1D()) lm = LinearMapper() colorbar = ColorBar(orientation=orientation, resizable=resizable, width=width, padding=padding, index_mapper=lm, color_mapper=cm) if plot is not None: colorbar.trait_set(index_mapper=LinearMapper(range=plot.color_mapper.range), color_mapper=plot.color_mapper, plot=plot) return colorbar
def _create_plot_component(model): # Create a plot data object and give it the model's data array. pd = ArrayPlotData() pd.set_data("imagedata", model.data) # Create the "main" Plot. plot = Plot(pd, padding=50) # Use a TransformColorMapper for the color map. tcm = TransformColorMapper.from_color_map(jet) # Create the image plot renderer in the main plot. renderer = plot.img_plot("imagedata", xbounds=model.x_array, ybounds=model.y_array, colormap=tcm)[0] # Create the colorbar. lm = LinearMapper(range=renderer.value_range, domain_limits=(renderer.value_range.low, renderer.value_range.high)) colorbar = ColorBar(index_mapper=lm, plot=plot, orientation='v', resizable='v', width=30, padding=20) 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(use_backbuffer = True) container.add(plot) container.add(colorbar) return container
def create_plot(self): # Create the mapper, etc self._image_index = GridDataSource(array([]), array([]), sort_order=("ascending", "ascending")) image_index_range = DataRange2D(self._image_index) # self._image_index.on_trait_change(self._metadata_changed, # "metadata_changed") self._image_value = ImageData(data=array([]), value_depth=1) image_value_range = DataRange1D(self._image_value) # Create the colormapped scalar plot self.plot = CMapImagePlot( index=self._image_index, index_mapper=GridMapper(range=image_index_range), value=self._image_value, value_mapper=self._cmap(image_value_range)) # Add a left axis to the plot left = PlotAxis(orientation='left', title="y", mapper=self.plot.index_mapper._ymapper, component=self.plot) self.plot.overlays.append(left) # Add a bottom axis to the plot bottom = PlotAxis(orientation='bottom', title="x", mapper=self.plot.index_mapper._xmapper, component=self.plot) self.plot.overlays.append(bottom) # Add some tools to the plot self.plot.tools.append(PanTool(self.plot, constrain_key="shift")) self.plot.overlays.append( ZoomTool(component=self.plot, tool_mode="box", always_on=False)) # Create a colorbar cbar_index_mapper = LinearMapper(range=image_value_range) self.colorbar = ColorBar(index_mapper=cbar_index_mapper, plot=self.plot, padding_top=self.plot.padding_top, padding_bottom=self.plot.padding_bottom, padding_right=40, resizable='v', width=10) # Create a container and add components self.container = HPlotContainer(padding=40, fill_padding=True, bgcolor="white", use_backbuffer=False) self.container.add(self.colorbar) self.container.add(self.plot)
def _RegionsPlot_default(self): plotdata = ArrayPlotData(imagedata=self.RegionsAndLabels[0], x=self.XPositions, y=self.YPositions) plot = Plot(plotdata, width=500, height=500, resizable='hv') RegionsImage = plot.img_plot( 'imagedata', colormap=gray, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), )[0] RegionsImage.x_mapper.domain_limits = (self.X[0], self.X[-1]) RegionsImage.y_mapper.domain_limits = (self.Y[0], self.Y[-1]) RegionsImage.overlays.append(ZoomTool(RegionsImage)) scatterplot = plot.plot(('x', 'y'), type='scatter', marker='plus', color='yellow') colormap = RegionsImage.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=10, padding=20) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom self.RegionsData = plotdata self.RegionsImage = RegionsImage container = HPlotContainer(padding=20, fill_padding=True, use_backbuffer=True) container.add(colorbar) container.add(plot) return container
def make_colorbar(self, plot, width=30, padding=20, orientation='v', resizable='v'): cm = gray(DataRange1D()) lm = LinearMapper() colorbar = ColorBar(orientation=orientation, resizable=resizable, width=width, padding=padding, index_mapper=lm, color_mapper=cm) if plot is not None: colorbar.trait_set( index_mapper=LinearMapper(range=plot.color_mapper.range), color_mapper=plot.color_mapper, plot=plot) return colorbar
def _create_colorbar(colormap, tools=[]): colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', width=30, padding=20) if 'colorbar' in tools: colorbar.tools.append(RangeSelection(component=colorbar)) colorbar.overlays.append(RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) return colorbar
def _container_default(self): plot = self.plot colormap = plot.color_mapper colorbar = ColorBar(index_mapper = LinearMapper(range=colormap.range), color_mapper = colormap, plot = plot, orientation = 'v', resizable = 'v', width = 30, padding = 20) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom container = HPlotContainer(bgcolor = 'lightgray', use_backbuffer = True) container.add(plot) container.add(colorbar) inspector = plot.plots['image'][0].tools[0] overlay = ImageInspectorOverlay(component = container, image_inspector = inspector, bgcolor = 'white', border_visible = True) container.overlays.append(overlay) return container
def create_colorbar(colormap): colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='', height=400, width=30, padding=20) colorbar.tools.append(RangeSelection(component=colorbar)) colorbar.overlays.append( RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) colorbar.tools.append(MoveTool(colorbar, drag_button="left")) return colorbar
def recompute_colorbar(self, plot): """ Create a colorbar for the image plot provided, and add to plot1_2d_container """ img_renderer = plot.plots["img_cost"][0] colormap = img_renderer.color_mapper # Constant mapper for the color bar so that the colors stay the same # even when different slices are selected-= index_mapper = LinearMapper(range=self.colorbar_range) self.colorbar = ColorBar(index_mapper=index_mapper, color_mapper=colormap, padding_top=plot.padding_top, padding_bottom=plot.padding_bottom, padding_right=20, resizable='v', orientation='v', width=30)
def _corr_plot_default(self): diag = self.covar.diagonal() corr = self.covar / np.sqrt(np.outer(diag, diag)) N = len(diag) value_range = DataRange1D(low=-1, high=1) color_mapper = cmap(range=value_range) index = GridDataSource() value = ImageData() mapper = GridMapper(range=DataRange2D(index), y_low_pos=1.0, y_high_pos=0.0) index.set_data(xdata=np.arange(-0.5, N), ydata=np.arange(-0.5, N)) value.set_data(np.flipud(corr)) self.corr_data = value cmap_plot = CMapImagePlot(index=index, index_mapper=mapper, value=value, value_mapper=color_mapper, padding=(40, 40, 100, 40)) yaxis = PlotAxis( cmap_plot, orientation='left', tick_interval=1, tick_label_formatter=lambda x: self.header[int(N - 1 - x)], tick_generator=ShowAllTickGenerator(positions=np.arange(N))) xaxis = PlotAxis( cmap_plot, orientation='top', tick_interval=1, tick_label_formatter=lambda x: self.header[int(x)], tick_label_alignment='edge', tick_generator=ShowAllTickGenerator(positions=np.arange(N))) cmap_plot.overlays.append(yaxis) cmap_plot.overlays.append(xaxis) colorbar = ColorBar( index_mapper=LinearMapper(range=cmap_plot.value_range), plot=cmap_plot, orientation='v', resizable='v', width=10, padding=(40, 5, 100, 40)) container = HPlotContainer(bgcolor='transparent') container.add(cmap_plot) container.add(colorbar) return container
def _figure_image_default(self): plot = Plot(self.plot_data_image, width=100, height=100, padding=8, padding_left=48, padding_bottom=32) plot.img_plot('image', colormap=RdBu_r, name='image') plot.aspect_ratio = 1 plot.index_mapper.domain_limits = (self.imager.get_x_range()[0], self.imager.get_x_range()[1]) plot.value_mapper.domain_limits = (self.imager.get_y_range()[0], self.imager.get_y_range()[1]) plot_fit = Plot(self.plot_data_image, width=100, height=100, padding=8, padding_left=48, padding_bottom=32) plot_fit.img_plot('fit', colormap=RdBu_r, name='fit') plot_fit.aspect_ratio = 1 plot_fit.index_mapper.domain_limits = (self.imager.get_x_range()[0], self.imager.get_x_range()[1]) plot_fit.value_mapper.domain_limits = (self.imager.get_y_range()[0], self.imager.get_y_range()[1]) container = HPlotContainer() image = plot.plots['image'][0] colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(plot_fit) container.add(colorbar) container.overlays.append(self.image_label) container.tools.append(SaveTool(container)) return container
def _create_plot(self): plot_data = ArrayPlotData(image=self.image) plot = Plot(plot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) plot.img_plot('image', colormap=jet, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), name='image') image = plot.plots['image'][0] fitplot_data = ArrayPlotData(fitimage=self.fitimage) fitplot = Plot(fitplot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) fitplot.img_plot('fitimage', colormap=jet, xbounds=(self.Xfit[0], self.Xfit[-1]), ybounds=(self.Yfit[0], self.Yfit[-1]), name='fitimage') fitplot.overlays.insert( 0, PlotLabel(text=self.label_text, hjustify='right', vjustify='bottom', position=[880, 590])) fitimage = fitplot.plots['fitimage'][0] image.x_mapper.domain_limits = (self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) image.y_mapper.domain_limits = (self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) fitimage.x_mapper.domain_limits = ( self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) fitimage.y_mapper.domain_limits = ( self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(colorbar) container.add(fitplot) container.tools.append(SaveTool(container)) self.plot_data = plot_data self.scan_plot = image self.figure = plot self.fitplot_data = fitplot_data self.fitscan_plot = fitimage self.fitfigure = fitplot self.figure_container = container
def _create_plot_component(): # Create a scalar field to colormap x_extents = (-2 * pi, 2 * pi) y_extents = (-1.5 * pi, 1.5 * pi) xs = linspace(-2 * pi, 2 * pi, 200) ys = linspace(-1.5 * pi, 1.5 * pi, 100) x, y = meshgrid(xs, ys) zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \ sin(((x+1)**2 + y**2)/4) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", zs) # Create the left plot, a colormap and simple contours lplot = Plot(pd) lplot.img_plot("imagedata", name="cm_plot", xbounds=x_extents, ybounds=y_extents, colormap=gmt_drywet) lplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents) # Tweak some of the plot properties lplot.title = "Colormap and contours" lplot.padding = 20 lplot.bg_color = "white" lplot.fill_padding = True # Add some tools to the plot zoom = ZoomTool(lplot, tool_mode="box", always_on=False) lplot.overlays.append(zoom) lplot.tools.append(PanTool(lplot, constrain_key="shift")) # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them cm_plot = lplot.plots["cm_plot"][0] # Create the colorbar, handing in the appropriate range and colormap colormap = cm_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=cm_plot, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = lplot.padding_top colorbar.padding_bottom = lplot.padding_bottom # Create the left plot, contours of varying color and width rplot = Plot(pd, range2d=lplot.range2d) rplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents, bgcolor="black", levels=15, styles="solid", widths=list(linspace(4.0, 0.1, 15)), colors=gmt_drywet) # Add some tools to the plot zoom = ZoomTool(rplot, tool_mode="box", always_on=False) rplot.overlays.append(zoom) rplot.tools.append(PanTool(rplot, constrain_key="shift")) # Tweak some of the plot properties rplot.title = "Varying contour lines" rplot.padding = 20 rplot.bg_color = "white" rplot.fill_padding = True # Create a container and add our plots container = HPlotContainer(padding=40, fill_padding=True, bgcolor="white", use_backbuffer=True) container.add(colorbar) container.add(lplot) container.add(rplot) return 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(self): # Create the mapper, etc self._image_index = GridDataSource(array([]), array([]), sort_order=("ascending","ascending")) image_index_range = DataRange2D(self._image_index) self._image_index.on_trait_change(self._metadata_changed, "metadata_changed") self._image_value = ImageData(data=array([]), value_depth=1) image_value_range = DataRange1D(self._image_value) # Create the contour plots self.polyplot = ContourPolyPlot(index=self._image_index, value=self._image_value, index_mapper=GridMapper(range= image_index_range), color_mapper=\ self._cmap(image_value_range), levels=self.num_levels) self.lineplot = ContourLinePlot(index=self._image_index, value=self._image_value, index_mapper=GridMapper(range= self.polyplot.index_mapper.range), levels=self.num_levels) # Add a left axis to the plot left = PlotAxis(orientation='left', title= "y", mapper=self.polyplot.index_mapper._ymapper, component=self.polyplot) self.polyplot.overlays.append(left) # Add a bottom axis to the plot bottom = PlotAxis(orientation='bottom', title= "x", mapper=self.polyplot.index_mapper._xmapper, component=self.polyplot) self.polyplot.overlays.append(bottom) # Add some tools to the plot self.polyplot.tools.append(PanTool(self.polyplot, constrain_key="shift")) self.polyplot.overlays.append(ZoomTool(component=self.polyplot, tool_mode="box", always_on=False)) self.polyplot.overlays.append(LineInspector(component=self.polyplot, axis='index_x', inspect_mode="indexed", write_metadata=True, is_listener=True, color="white")) self.polyplot.overlays.append(LineInspector(component=self.polyplot, axis='index_y', inspect_mode="indexed", write_metadata=True, color="white", is_listener=True)) # Add these two plots to one container contour_container = OverlayPlotContainer(padding=20, use_backbuffer=True, unified_draw=True) contour_container.add(self.polyplot) contour_container.add(self.lineplot) # Create a colorbar cbar_index_mapper = LinearMapper(range=image_value_range) self.colorbar = ColorBar(index_mapper=cbar_index_mapper, plot=self.polyplot, padding_top=self.polyplot.padding_top, padding_bottom=self.polyplot.padding_bottom, padding_right=40, resizable='v', width=30) self.pd = ArrayPlotData(line_index = array([]), line_value = array([]), scatter_index = array([]), scatter_value = array([]), scatter_color = array([])) self.cross_plot = Plot(self.pd, resizable="h") self.cross_plot.height = 100 self.cross_plot.padding = 20 self.cross_plot.plot(("line_index", "line_value"), line_style="dot") self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"), type="cmap_scatter", name="dot", color_mapper=self._cmap(image_value_range), marker="circle", marker_size=8) self.cross_plot.index_range = self.polyplot.index_range.x_range self.pd.set_data("line_index2", array([])) self.pd.set_data("line_value2", array([])) self.pd.set_data("scatter_index2", array([])) self.pd.set_data("scatter_value2", array([])) self.pd.set_data("scatter_color2", array([])) self.cross_plot2 = Plot(self.pd, width = 140, orientation="v", resizable="v", padding=20, padding_bottom=160) self.cross_plot2.plot(("line_index2", "line_value2"), line_style="dot") self.cross_plot2.plot(("scatter_index2","scatter_value2","scatter_color2"), type="cmap_scatter", name="dot", color_mapper=self._cmap(image_value_range), marker="circle", marker_size=8) self.cross_plot2.index_range = self.polyplot.index_range.y_range # Create a container and add components self.container = HPlotContainer(padding=40, fill_padding=True, bgcolor = "white", use_backbuffer=False) inner_cont = VPlotContainer(padding=0, use_backbuffer=True) inner_cont.add(self.cross_plot) inner_cont.add(contour_container) self.container.add(self.colorbar) self.container.add(inner_cont) self.container.add(self.cross_plot2)
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(self): plot_data = ArrayPlotData(image=self.image) plot = Plot(plot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) plot.img_plot('image', colormap=jet, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), name='image') image = plot.plots['image'][0] bwplot_data = ArrayPlotData(bwimage=self.bwimage) bwplot = Plot(bwplot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) bwplot.img_plot('bwimage', colormap=jet, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), name='bwimage') bwimage = bwplot.plots['bwimage'][0] image.x_mapper.domain_limits = (self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) image.y_mapper.domain_limits = (self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) bwimage.x_mapper.domain_limits = (self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) bwimage.y_mapper.domain_limits = (self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(colorbar) container.add(bwplot) container.tools.append(SaveTool(container)) self.plot_data = plot_data self.scan_plot = image self.figure = plot self.bwplot_data = bwplot_data self.bwscan_plot = bwimage self.bwfigure = bwplot self.figure_container = container
def _myTIC_default( self ): # create an interesting scalar field for the image plot # Eggholder function limitF = 500.0 xA = linspace(-limitF, limitF, 600) yA = linspace(-limitF, limitF, 600) ( xMG,yMG ) = meshgrid( xA,yA ) zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) # Create an ArrayPlotData object and give it this data myAPD = ArrayPlotData() myAPD.set_data( "Z", zMG ) myAPD.set_data( "X",xA ) myAPD.set_data( "Y",yA ) # Create the plot myTP = Plot( myAPD ) # contains a dict of default colormaps and their functions. We have to # pass the colormapper the data range of interest to set up the private # attributes default_colormaps.color_map_name_dict # the colormap method needs the range of the image data that we want to # plot. We first put the image data (zMG) into an ImageData object. We # then use DataRange1D on the ImageData instance to produce a DataRange1D # instance describing the ImageData data. Finally, we feed the DataRange1D # instance into the colormapper to produce a working colormapper. myID = ImageData( ) myID.set_data( zMG ) myDR1D = DataRange1D( myID ) # pick a colormap myColorMapperFn = default_colormaps.color_map_name_dict['copper'] # choose one or more modifications to the colormap function #myColorMapperFn = default_colormaps.reverse( myColorMapperFn ) #myColorMapperFn = default_colormaps.center( myColorMapperFn,500 ) #myColorMapperFn = default_colormaps.fix( myColorMapperFn,(-500,500) ) # finally, build the colormapper function myColorMapper = myColorMapperFn( myDR1D ) # add the image plot to this plot object # specify the colormap explicitly myTP.img_plot( "Z", xbounds = (xA[0],xA[-1]), ybounds = (yA[0],yA[-1]), colormap = myColorMapper, ) # add the title and padding around the plot myTP.title = "Eggholder Function" myTP.padding = 50 # grids, fonts, etc myTP.x_axis.title = "X" myTP.y_axis.title = "Y" # generate a ColorBar. pulls its colormapper from the myTP Plot object myTCB = ColorBar( plot = myTP, index_mapper = LinearMapper( range = myTP.color_mapper.range ), orientation = 'v', resizable = 'v', width = 40, padding = 30, ) # set the padding of the ColorBar to match the padding of the plot myTCB.padding_top = myTP.padding_top myTCB.padding_bottom = myTP.padding_bottom # range of the colormapper. Changes the min/max values that are mapped # to the ends of the color range. Try +/-2000 for poor contrast and +/-200 for # saturated. Asymmetrical values work as well. #myTP.color_mapper.range.low_setting = 0 #myTP.color_mapper.range.high_setting = 1000 # build up a single container for the colorbar and the image myHPC = HPlotContainer( use_backbuffer = True ) myHPC.add( myTP ) myHPC.add( myTCB ) return( myHPC )
def _create_plot_component(): # Create a scalar field to colormap# Create a scalar field to colormap xbounds = (-2 * pi, 2 * pi, 600) ybounds = (-1.5 * pi, 1.5 * pi, 300) xs = linspace(*xbounds) ys = linspace(*ybounds) x, y = meshgrid(xs, ys) z = jn(2, x) * y * x # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) plot.img_plot( "imagedata", name="my_plot", xbounds=xbounds[:2], ybounds=ybounds[:2], colormap=jet) # Tweak some of the plot properties plot.title = "Selectable Image Plot" plot.padding = 50 # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them my_plot = plot.plots["my_plot"][0] # 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) # Create the colorbar, handing in the appropriate range and colormap colormap = my_plot.color_mapper colorbar = ColorBar( index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=my_plot, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # create a range selection for the colorbar range_selection = RangeSelection(component=colorbar) colorbar.tools.append(range_selection) colorbar.overlays.append( RangeSelectionOverlay( component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) # we also want to the range selection to inform the cmap plot of # the selection, so set that up as well range_selection.listeners.append(my_plot) # 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" #my_plot.set_value_selection((-1.3, 6.9)) return container
def _create_plot_component(): # Create a scalar field to colormap x_extents = (-2*pi, 2*pi) y_extents = (-1.5*pi, 1.5*pi) xs = linspace(-2*pi, 2*pi, 200) ys = linspace(-1.5*pi, 1.5*pi, 100) x, y = meshgrid(xs,ys) zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \ sin(((x+1)**2 + y**2)/4) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", zs) # Create the left plot, a colormap and simple contours lplot = Plot(pd) lplot.img_plot("imagedata", name="cm_plot", xbounds=x_extents, ybounds=y_extents, colormap=gmt_drywet) lplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents) # Tweak some of the plot properties lplot.title = "Colormap and contours" lplot.padding = 20 lplot.bg_color = "white" lplot.fill_padding = True # Add some tools to the plot zoom = ZoomTool(lplot, tool_mode="box", always_on=False) lplot.overlays.append(zoom) lplot.tools.append(PanTool(lplot, constrain_key="shift")) # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them cm_plot = lplot.plots["cm_plot"][0] # Create the colorbar, handing in the appropriate range and colormap colormap = cm_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=cm_plot, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = lplot.padding_top colorbar.padding_bottom = lplot.padding_bottom # Create the left plot, contours of varying color and width rplot = Plot(pd, range2d=lplot.range2d) rplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents, bgcolor="black", levels=15, styles="solid", widths=list(linspace(4.0, 0.1, 15)), colors=gmt_drywet) # Add some tools to the plot zoom = ZoomTool(rplot, tool_mode="box", always_on=False) rplot.overlays.append(zoom) rplot.tools.append(PanTool(rplot, constrain_key="shift")) # Tweak some of the plot properties rplot.title = "Varying contour lines" rplot.padding = 20 rplot.bg_color = "white" rplot.fill_padding = True # Create a container and add our plots container = HPlotContainer(padding=40, fill_padding=True, bgcolor = "white", use_backbuffer=True) container.add(colorbar) container.add(lplot) container.add(rplot) return container
def __init__(self, x, y, z): super(ImagePlot, self).__init__() self.pd_all = ArrayPlotData(imagedata=z) #self.pd_horiz = ArrayPlotData(x=x, horiz=z[4, :]) #self.pd_vert = ArrayPlotData(y=y, vert=z[:,5]) self._imag_index = GridDataSource(xdata=x, ydata=y, sort_order=("ascending", "ascending")) index_mapper = GridMapper(range=DataRange2D(self._imag_index)) self._imag_index.on_trait_change(self._metadata_changed, "metadata_changed") self._image_value = ImageData(data=z, value_depth=1) color_mapper = jet(DataRange1D(self._image_value)) self.color_plot = CMapImagePlot(index=self._imag_index, index_mapper=index_mapper, value=self._image_value, value_mapper=color_mapper, padding=20, use_backbuffer=True, unified_draw=True) #Add axes to image plot left = PlotAxis(orientation='left', title="Frequency (GHz)", mapper=self.color_plot.index_mapper._ymapper, component=self.color_plot) self.color_plot.overlays.append(left) bottom = PlotAxis(orientation='bottom', title="Time (us)", mapper=self.color_plot.index_mapper._xmapper, component=self.color_plot) self.color_plot.overlays.append(bottom) self.color_plot.tools.append( PanTool(self.color_plot, constrain_key="shift")) self.color_plot.overlays.append( ZoomTool(component=self.color_plot, tool_mode="box", always_on=False)) #Add line inspector tool for horizontal and vertical self.color_plot.overlays.append( LineInspector(component=self.color_plot, axis='index_x', inspect_mode="indexed", write_metadata=True, is_listener=True, color="white")) self.color_plot.overlays.append( LineInspector(component=self.color_plot, axis='index_y', inspect_mode="indexed", write_metadata=True, color="white", is_listener=True)) myrange = DataRange1D(low=amin(z), high=amax(z)) cmap = jet self.colormap = cmap(myrange) # Create a colorbar cbar_index_mapper = LinearMapper(range=myrange) self.colorbar = ColorBar(index_mapper=cbar_index_mapper, plot=self.color_plot, padding_top=self.color_plot.padding_top, padding_bottom=self.color_plot.padding_bottom, padding_right=40, resizable='v', width=30) #, ytitle="Magvec (mV)") #create horizontal line plot self.horiz_cross_plot = Plot(self.pd_horiz, resizable="h") self.horiz_cross_plot.height = 100 self.horiz_cross_plot.padding = 20 self.horiz_cross_plot.plot(("x", "horiz")) #, #line_style="dot") # self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"), # type="cmap_scatter", # name="dot", # color_mapper=self._cmap(image_value_range), # marker="circle", # marker_size=8) self.horiz_cross_plot.index_range = self.color_plot.index_range.x_range #create vertical line plot self.vert_cross_plot = Plot(self.pd_vert, width=140, orientation="v", resizable="v", padding=20, padding_bottom=160) self.vert_cross_plot.plot(("y", "vert")) #, # line_style="dot") # self.vert_cross_plot.xtitle="Magvec (mV)" # self.vertica_cross_plot.plot(("vertical_scatter_index", # "vertical_scatter_value", # "vertical_scatter_color"), # type="cmap_scatter", # name="dot", # color_mapper=self._cmap(image_value_range), # marker="circle", # marker_size=8) self.vert_cross_plot.index_range = self.color_plot.index_range.y_range # Create a container and add components self.container = HPlotContainer(padding=40, fill_padding=True, bgcolor="white", use_backbuffer=False) inner_cont = VPlotContainer(padding=0, use_backbuffer=True) inner_cont.add(self.horiz_cross_plot) inner_cont.add(self.color_plot) self.container.add(self.colorbar) self.container.add(inner_cont) self.container.add(self.vert_cross_plot)
def _create_plot_components(): # Create the data and datasource objects # In order for the date axis to work, the index data points need to # be in units of seconds since the epoch. This is because we are using # the CalendarScaleSystem, whose formatters interpret the numerical values # as seconds since the epoch. high = 1. numpoints = 5000 random.seed(1000) index = create_dates(numpoints) price = 100 * cumprod(random.lognormal(0.0, 0.04, size=numpoints)) changes = price / price[0] - 1. index_ds = ArrayDataSource(index) value_ds = ArrayDataSource(changes, sort_order="none") value_range = DataRange1D(value_ds, low=-high, high=high) index_mapper = LinearMapper(range=DataRange1D(index_ds), stretch_data=False) horizon = HorizonPlot( bands=4, index=index_ds, value=value_ds, index_mapper=index_mapper, value_mapper=BandedMapper(range=DataRange1D(low=0, high=high)), color_mapper=cmap(range=value_range), ) horizon.tools.append( PanTool(horizon, constrain=True, constrain_direction="x")) axis = PlotAxis(mapper=horizon.value_mapper, component=horizon, orientation="left", tick_label_position="outside") horizon.overlays.append(axis) bottom_axis = PlotAxis( horizon, orientation="bottom", tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem())) horizon.overlays.append(bottom_axis) filled = FilledLinePlot( index=index_ds, value=value_ds, index_mapper=index_mapper, value_mapper=LinearMapper(range=value_range, stretch_data=False), fill_color=(0.81960784, 0.89803922, 0.94117647), edge_color='transparent', ) filled.tools.append( PanTool(filled, constrain=True, constrain_direction="x")) axis = PlotAxis(mapper=filled.value_mapper, component=filled, orientation="left", tick_label_position="outside") filled.overlays.append(axis) grid = PlotGrid( mapper=filled.value_mapper, component=filled, orientation='horizontal', line_color='lightgray', line_style="dot", ) filled.underlays.append(grid) colormap = horizon.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', width=20, padding=20) padding = (40, 20, 0, 0) over1 = HPlotContainer(use_backbuffer=True, padding=padding, padding_top=20) over1.add(filled) over1.add(colorbar) over2 = OverlayPlotContainer(padding=padding, padding_bottom=40) over2.add(horizon) return over1, over2
def _create_plot_component_cmap(signals): nSignal, nSample = np.shape(signals) xbounds = (1, nSample, nSample) ybounds = (1, nSignal, nSignal) z = signals # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) plot.img_plot("imagedata", name="my_plot", xbounds=xbounds[:2], ybounds=ybounds[:2], colormap=jet) # Tweak some of the plot properties plot.title = "Selectable Image Plot" # plot.padding = 50 # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them my_plot = plot.plots["my_plot"][0] # 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) # Create the colorbar, handing in the appropriate range and colormap colormap = my_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=my_plot, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # create a range selection for the colorbar range_selection = RangeSelection(component=colorbar) colorbar.tools.append(range_selection) colorbar.overlays.append(RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) # we also want to the range selection to inform the cmap plot of # the selection, so set that up as well range_selection.listeners.append(my_plot) # 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(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 = 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 _plot(self, x, y, z, scale): pd = ArrayPlotData() pd.set_data("imagedata", z) plot = Plot(pd, padding_left=60, fill_padding=True) plot.bgcolor = 'white' cmap = fix(jet, (0, z.max())) origin = 'bottom left' # origin = 'top left' # to flip y-axis plot.img_plot("imagedata", name="surface2d", xbounds=(np.min(x), np.max(x)), ybounds=(1.0, y[-1,-1]), colormap=cmap, hide_grids=True, interpolation='nearest', origin=origin, ) plot.default_origin = origin plot.x_axis.title = u'Angle (2\u0398)' tick_font = settings.tick_font plot.x_axis.title_font = settings.axis_title_font plot.y_axis.title_font = settings.axis_title_font plot.x_axis.tick_label_font = tick_font plot.y_axis.tick_label_font = tick_font plot.y_axis.title = "Dataset" plot.y_axis.tick_interval = 1.0 actual_plot = plot.plots["surface2d"][0] self.plot_zoom_tool = ClickUndoZoomTool( plot, tool_mode="box", always_on=True, pointer="cross", drag_button=settings.zoom_button, undo_button=settings.undo_button, x_min_zoom_factor=-np.inf, y_min_zoom_factor=-np.inf, ) plot.overlays.append(self.plot_zoom_tool) plot.tools.append(TraitsTool(plot)) # Add a color bar colormap = actual_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=actual_plot, orientation='v', resizable='v', width=30, padding=40, padding_top=50, fill_padding=True) colorbar._axis.title_font = settings.axis_title_font colorbar._axis.tick_label_font = settings.tick_font # Add pan and zoom tools to the colorbar self.colorbar_zoom_tool = ClickUndoZoomTool(colorbar, axis="index", tool_mode="range", always_on=True, drag_button=settings.zoom_button, undo_button=settings.undo_button) pan_tool = PanToolWithHistory(colorbar, history_tool=self.colorbar_zoom_tool, constrain_direction="y", constrain=True, drag_button=settings.pan_button) colorbar.tools.append(pan_tool) colorbar.overlays.append(self.colorbar_zoom_tool) # Add a label to the top of the color bar colorbar_label = PlotLabel( u'Intensity\n{:^9}'.format('(' + get_value_scale_label(scale) + ')'), component=colorbar, font=settings.axis_title_font, ) colorbar.overlays.append(colorbar_label) colorbar.tools.append(TraitsTool(colorbar)) # Add the plot and colorbar side-by-side container = HPlotContainer(use_backbuffer=True) container.add(plot) container.add(colorbar) return container
def _brain_default(self): plot = Plot(self.brain_data, padding=0) plot.width = self.brain_voxels.shape[1] plot.height = self.brain_voxels.shape[0] plot.aspect_ratio = 1. plot.index_axis.visible = False plot.value_axis.visible = False renderer = plot.img_plot("axial", colormap=gray)[0] plot.color_mapper.range = DataRange1D(low=0., high=1.0) plot.bgcolor = 'pink' # Brain tools plot.tools.append(PanTool(plot, drag_button="right")) plot.tools.append(ZoomTool(plot)) imgtool = ImageInspectorTool(renderer) renderer.tools.append(imgtool) overlay = ImageInspectorOverlay(component=renderer, image_inspector=imgtool, bgcolor="white", border_visible=True) renderer.overlays.append(overlay) # Brain track cursor self.cursor = CursorTool2D(renderer, drag_button='left', color='red', line_width=2.0) #self.cursor.on_trait_change(self.update_stackedhist, 'current_index') self.cursor.current_positionyou = (0., 0.) renderer.overlays.append(self.cursor) # Brain colorbar colormap = plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=20, padding=(30, 0, 0, 0)) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # Noisy brain plot2 = Plot(self.brain_data, padding=0) plot2.width = self.brain_voxels.shape[1] plot2.height = self.brain_voxels.shape[0] plot2.aspect_ratio = 1. plot2.index_axis.visible = False plot2.value_axis.visible = False renderer2 = plot2.img_plot("noisy_axial", colormap=gray)[0] plot2.color_mapper.range = DataRange1D(low=0., high=1.0) plot2.bgcolor = 'pink' plot2.range2d = plot.range2d # Brain_map tools plot2.tools.append(PanTool(plot2, drag_button="right")) plot2.tools.append(ZoomTool(plot2)) imgtool2 = ImageInspectorTool(renderer2) renderer2.tools.append(imgtool2) overlay2 = ImageInspectorOverlay(component=renderer2, image_inspector=imgtool2, bgcolor="white", border_visible=True) renderer2.overlays.append(overlay2) # Brain_map track cursor self.cursor2 = CursorTool2D(renderer2, drag_button='left', color='red', line_width=2.0) #self.cursor2.on_trait_change(self.cursor2_changed, 'current_index') self.cursor2.current_position = (0., 0.) renderer2.overlays.append(self.cursor2) # Brain_map colorbar colormap2 = plot2.color_mapper colorbar2 = ColorBar(index_mapper=LinearMapper(range=colormap2.range), color_mapper=colormap2, plot=plot2, orientation='v', resizable='v', width=20, padding=(30, 0, 0, 0)) colorbar2.padding_top = plot2.padding_top colorbar2.padding_bottom = plot2.padding_bottom # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10)) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" container2 = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10)) container2.add(plot2) container2.add(colorbar2) container2.bgcolor = "lightgray" Hcontainer = HPlotContainer(use_backbuffer=True) Hcontainer.add(container) Hcontainer.add(container2) Hcontainer.bgcolor = "lightgray" return Hcontainer