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 _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 _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 _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 __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 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 _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 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 create_colorbar(colormap): colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', width=30, padding=20) return colorbar
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 create_colorbar(colormap): colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', resizable='v', 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")) 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 _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 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 _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 _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_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_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(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 __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 _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 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(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 _get_plot_cmap(self): if self.data is None or len(self.data.shape) == 1: return numpoints = self.data.shape[1] if self.scale_type == 'Time': index_x = self._create_dates(numpoints, start=self.first_day) else: index_x = np.arange(numpoints) x_bounds = (index_x[0], index_x[-1], len(index_x)) y_bounds = (1, self.data.shape[0], self.data.shape[0]) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", self.data) plot = Plot(pd) plot.img_plot("imagedata", name="corr_plot", origin="top left", xbounds=x_bounds[:2], ybounds=y_bounds[:2], colormap=jet, padding_left=25) corr_plot = plot.plots['corr_plot'][0] if self.scale_type == 'Time': # Just the last axis shows tick_labels bottom_axis = PlotAxis(corr_plot, orientation="bottom", title=self.x_lbl, tick_generator=ScalesTickGenerator( scale=CalendarScaleSystem())) else: bottom_axis = PlotAxis(orientation='bottom', title=self.x_lbl, title_font="modern 12", tick_visible=True, small_axis_style=True, axis_line_visible=False, component=corr_plot) corr_plot.overlays.append(bottom_axis) corr_plot.tools.append( PanTool(corr_plot, constrain=True, constrain_direction="x", constrain_key="shift")) corr_plot.overlays.append( ZoomTool( corr_plot, drag_button="right", always_on=True, tool_mode="range", axis="index", max_zoom_out_factor=10.0, )) # Create the colorbar, handing in the appropriate range and colormap colorbar = ColorBar( index_mapper=LinearMapper(range=corr_plot.color_mapper.range), color_mapper=corr_plot.color_mapper, plot=corr_plot, orientation='v', resizable='v', width=30, padding_top=corr_plot.padding_top, padding_bottom=corr_plot.padding_bottom, padding_left=50, padding_right=5) #colorbar.plot = corr_plot #colorbar.padding_top = corr_plot.padding_top #colorbar.padding_bottom = corr_plot.padding_bottom # Add pan and zoom tools to the colorbar pan_tool = PanTool(colorbar, constrain_direction="y", constrain=True) colorbar.tools.append(pan_tool) zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range", always_on=False, drag_button=None) colorbar.overlays.append(zoom_overlay) # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(corr_plot, colorbar, use_backbuffer=True, bgcolor="transparent", spacing=9, padding=30) container.overlays.append( PlotLabel(self.p_title, component=container, overlay_position="outside top", font="modern 16")) container.overlays.append( PlotLabel(self.y_lbl, component=container, angle=90.0, overlay_position="outside left", font="modern 12")) container.padding_bottom = 50 return container
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 __init__(self, **kwtraits): super(ResultExplorer, self).__init__(**kwtraits) # containers bgcolor = "sys_window" #(212/255.,208/255.,200/255.) # Windows standard background self.plot_container = container = VPlotContainer(use_backbuffer=True, padding=0, fill_padding=False, valign="center", bgcolor=bgcolor) subcontainer = HPlotContainer(use_backbuffer=True, padding=0, fill_padding=False, halign="center", bgcolor=bgcolor) # freqs self.synth = FreqSelector(parent=self) # data source self.plot_data = pd = ArrayPlotData() self.set_result_data() self.set_pict() # map plot self.map_plot = Plot(pd, padding=40) self.map_plot.img_plot("image", name="image") imgp = self.map_plot.img_plot("map_data", name="map", colormap=jet)[0] self.imgp = imgp t1 = self.map_plot.plot(("xpoly", "ypoly"), name="sector", type="polygon") t1[0].face_color = (0, 0, 0, 0) # set face color to transparent # map plot tools and overlays imgtool = ImageInspectorTool(imgp) imgp.tools.append(imgtool) overlay = ImageInspectorOverlay(component=imgp, image_inspector=imgtool, bgcolor="white", border_visible=True) self.map_plot.overlays.append(overlay) self.zoom = RectZoomSelect(self.map_plot, drag_button='right', always_on=True, tool_mode='box') self.map_plot.overlays.append(self.zoom) self.map_plot.tools.append(PanTool(self.map_plot)) # colorbar colormap = imgp.color_mapper self.drange = colormap.range self.drange.low_setting = "track" self.colorbar = cb = ColorBar( index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=self.map_plot, orientation='v', resizable='v', width=10, padding=20) # colorbar tools and overlays range_selection = RangeSelection(component=cb) cb.tools.append(range_selection) cb.overlays.append( RangeSelectionOverlay(component=cb, border_color="white", alpha=0.8, fill_color=bgcolor)) range_selection.listeners.append(imgp) # spectrum plot self.spec_plot = Plot(pd, padding=25) px = self.spec_plot.plot(("freqs", "spectrum"), name="spectrum", index_scale="log")[0] self.yrange = self.spec_plot.value_range px.index_mapper = MyLogMapper(range=self.spec_plot.index_range) # spectrum plot tools self.cursor = CursorTool( px) #, drag_button="left", color='blue', show_value_line=False) px.overlays.append(self.cursor) self.cursor.current_position = 0.3, 0.5 px.index_mapper.map_screen(0.5) # self.map_plot.tools.append(SaveTool(self.map_plot, filename='pic.png')) # layout self.set_map_details() self.reset_sector() subcontainer.add(self.map_plot) subcontainer.add(self.colorbar) # subcontainer.tools.append(SaveTool(subcontainer, filename='pic.png')) container.add(self.spec_plot) container.add(subcontainer) container.tools.append(SaveTool(container, filename='pic.pdf')) self.last_valid_digest = self.Beamformer.ext_digest