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(self): cmap = self.plot.color_mapper self._colorbar = ColorBar(index_mapper=LinearMapper(range=cmap.range), color_mapper=cmap, orientation='v', resizable='v', width=30, padding=30)
def __init__(self, **kwargs): super(VariableMeshPannerView, self).__init__(**kwargs) # Create the plot self.add_trait("field", DelegatesTo("vm_plot")) plot = self.vm_plot.plot img_plot = self.vm_plot.img_plot if self.use_tools: plot.tools.append(PanTool(img_plot)) zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) 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) image_value_range = DataRange1D(self.vm_plot.fid) cbar_index_mapper = LinearMapper(range=image_value_range) self.colorbar = ColorBar(index_mapper=cbar_index_mapper, plot=img_plot, padding_right=40, resizable='v', width=30) self.colorbar.tools.append( PanTool(self.colorbar, constrain_direction="y", constrain=True)) zoom_overlay = ZoomTool(self.colorbar, axis="index", tool_mode="range", always_on=True, drag_button="right") self.colorbar.overlays.append(zoom_overlay) # create a range selection for the colorbar range_selection = RangeSelection(component=self.colorbar) self.colorbar.tools.append(range_selection) self.colorbar.overlays.append( RangeSelectionOverlay(component=self.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(img_plot) self.full_container = HPlotContainer(padding=30) self.container = OverlayPlotContainer(padding=0) self.full_container.add(self.colorbar) self.full_container.add(self.container) self.container.add(self.vm_plot.plot)
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_plot_component(self): # Create a plot data object and give it this data self.pd = ArrayPlotData() self.pd.set_data("imagedata", self.data[self.data_name]) # Create the plot self.tplot = Plot(self.pd, default_origin="top left") self.tplot.x_axis.orientation = "top" self.tplot.img_plot( "imagedata", name="my_plot", #xbounds=(0,10), #ybounds=(0,10), colormap=jet) # Tweak some of the plot properties self.tplot.title = "Matrix" self.tplot.padding = 50 # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them self.my_plot = self.tplot.plots["my_plot"][0] # Attach some tools to the plot self.tplot.tools.append(PanTool(self.tplot)) zoom = ZoomTool(component=self.tplot, tool_mode="box", always_on=False) self.tplot.overlays.append(zoom) # my custom tool to get the connection information self.custtool = CustomTool(self.tplot) self.tplot.tools.append(self.custtool) # Create the colorbar, handing in the appropriate range and colormap colormap = self.my_plot.color_mapper self.colorbar = ColorBar( index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=self.my_plot, orientation='v', resizable='v', width=30, padding=20) self.colorbar.padding_top = self.tplot.padding_top self.colorbar.padding_bottom = self.tplot.padding_bottom # create a range selection for the colorbar self.range_selection = RangeSelection(component=self.colorbar) self.colorbar.tools.append(self.range_selection) self.colorbar.overlays.append( RangeSelectionOverlay(component=self.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 self.range_selection.listeners.append(self.my_plot) # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(use_backbuffer=True) container.add(self.tplot) container.add(self.colorbar) container.bgcolor = "white" 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_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 = 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 __init__(self,xdata=None,ydata=None,weights=None,model=None, include_models=None,exclude_models=None,fittype=None,**traits): """ :param xdata: the first dimension of the data to be fit :type xdata: array-like :param ydata: the second dimension of the data to be fit :type ydata: array-like :param weights: The weights to apply to the data. Statistically interpreted as inverse errors (*not* inverse variance). May be any of the following forms: * None for equal weights * an array of points that must match `ydata` * a 2-sequence of arrays (xierr,yierr) such that xierr matches the `xdata` and yierr matches `ydata` * a function called as f(params) that returns an array of weights that match one of the above two conditions :param model: the initial model to use to fit this data :type model: None, string, or :class:`pymodelfit.core.FunctionModel1D` instance. :param include_models: With `exclude_models`, specifies which models should be available in the "new model" dialog (see `models.list_models` for syntax). :param exclude_models: With `include_models`, specifies which models should be available in the "new model" dialog (see `models.list_models` for syntax). :param fittype: The fitting technique for the initial fit (see :class:`pymodelfit.core.FunctionModel`). :type fittype: string kwargs are passed in as any additional traits to apply to the application. """ self.modelpanel = View(Label('empty'),kind='subpanel',title='model editor') self.tmodel = TraitedModel(model) if model is not None and fittype is not None: self.tmodel.model.fittype = fittype if xdata is None or ydata is None: if not hasattr(self.tmodel.model,'data') or self.tmodel.model.data is None: raise ValueError('data not provided and no data in model') if xdata is None: xdata = self.tmodel.model.data[0] if ydata is None: ydata = self.tmodel.model.data[1] if weights is None: weights = self.tmodel.model.data[2] self.on_trait_change(self._paramsChanged,'tmodel.paramchange') self.modelselector = NewModelSelector(include_models,exclude_models) self.data = [xdata,ydata] if weights is None: self.weights = np.ones_like(xdata) self.weighttype = 'equal' else: self.weights = np.array(weights,copy=True) self.savews = True weights1d = self.weights while len(weights1d.shape)>1: weights1d = np.sum(weights1d**2,axis=0) pd = ArrayPlotData(xdata=self.data[0],ydata=self.data[1],weights=weights1d) self.plot = plot = Plot(pd,resizable='hv') self.scatter = plot.plot(('xdata','ydata','weights'),name='data', color_mapper=_cmapblack if self.weights0rem else _cmap, type='cmap_scatter', marker='circle')[0] self.errorplots = None if not isinstance(model,FunctionModel1D): self.fitmodel = True self.updatemodelplot = False #force plot update - generates xmod and ymod plot.plot(('xmod','ymod'),name='model',type='line',line_style='dash',color='black',line_width=2) del plot.x_mapper.range.sources[-1] #remove the line plot from the x_mapper source so only the data is tied to the scaling self.on_trait_change(self._rangeChanged,'plot.index_mapper.range.updated') self.pantool = PanTool(plot,drag_button='left') plot.tools.append(self.pantool) self.zoomtool = ZoomTool(plot) self.zoomtool.prev_state_key = KeySpec('a') self.zoomtool.next_state_key = KeySpec('s') plot.overlays.append(self.zoomtool) self.scattertool = None self.scatter.overlays.append(ScatterInspectorOverlay(self.scatter, hover_color = "black", selection_color="black", selection_outline_color="red", selection_line_width=2)) self.colorbar = colorbar = ColorBar(index_mapper=LinearMapper(range=plot.color_mapper.range), color_mapper=plot.color_mapper.range, plot=plot, orientation='v', resizable='v', width = 30, padding = 5) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom colorbar._axis.title = 'Weights' self.plotcontainer = container = HPlotContainer(use_backbuffer=True) container.add(plot) container.add(colorbar) super(FitGui,self).__init__(**traits) self.on_trait_change(self._scale_change,'plot.value_scale,plot.index_scale') if weights is not None and len(weights)==2: self.weightsChanged() #update error bars
def create_plot_component(self): self.plot_data = ArrayPlotData() self.plot_data.set_data("imagedata", self.model.intens_yz) self.plot_data.set_data('vert_image',self.model.intens_xz) self.plot_data.set_data('beam_section', self.model.intens_xy) # Create a contour polygon plot of the data plot = Plot(self.plot_data) plot.title = 'Horizontal plane' plot.padding=5 plot.padding_top = 22 plot.padding_left=25 plot.padding_bottom=20 my_plot = plot.img_plot("imagedata", name='my_plot', # xbounds=x,#ybounds=y, colormap=jet, hide_grids=True)[0] colormap = my_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=my_plot, orientation='v', resizable='v', width=25, padding=0) colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom colorbar.padding_left = 35 colorbar.padding_right = 30 colorbar._axis.tick_label_formatter = lambda x: ('%.0e'%x) rplot = Plot(self.plot_data) rplot.title = 'Vertical plane' rplot.padding=plot.padding rplot.padding_top = plot.padding_top rplot.padding_left = plot.padding_left rplot.padding_bottom = plot.padding_bottom my_plot = rplot.img_plot('vert_image',name='vert_plot',colormap=jet)[0] colormap = my_plot.color_mapper colorbar_rplot = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=my_plot, orientation='v', resizable='v', width=25, padding=0) colorbar_rplot.padding_top = plot.padding_top colorbar_rplot.padding_bottom = plot.padding_bottom colorbar_rplot.padding_right = 20 colorbar_rplot.padding_left = 35 colorbar_rplot._axis.tick_label_formatter = lambda x: ('%.0e'%x) sec_plot = Plot(self.plot_data) sec_plot.title = 'Beam section' sec_plot.padding=plot.padding sec_plot.padding_top = plot.padding_top sec_plot.padding_left = plot.padding_left sec_plot.padding_bottom = plot.padding_bottom my_plot = sec_plot.img_plot('beam_section',name='beam_section_plot',colormap=jet)[0] colormap = my_plot.color_mapper colorbar_sec_plot = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=my_plot, orientation='v', resizable='v', width=25, padding=0) colorbar_sec_plot.padding_top = plot.padding_top colorbar_sec_plot.padding_bottom = plot.padding_bottom colorbar_sec_plot.padding_right = 20 colorbar_sec_plot.padding_left = 35 colorbar_sec_plot._axis.tick_label_formatter = lambda x: ('%.0e'%x) container = HPlotContainer(use_backbuffer = True) container.add(plot) container.add(colorbar) container.add(rplot) container.add(colorbar_rplot) container.add(sec_plot) container.add(colorbar_sec_plot) self.plot_container = container
def _create_plot_component(file_name): # Create a scalar field to colormap z = load(file_name) pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) plot.bgcolor = 'gray' img_plot = plot.img_plot("imagedata", name='my_plot', colormap=jet, hide_grids=True)[0] #cont_plot=plot.contour_plot('imagedata', type='line', name='countour') # Tweak some of the plot properties #plot.title = file_name plot.padding = 40 plot.padding_right=20 # Attach some tools to the plot plot.tools.append(PanTool(plot)) #plot.tools.append(TraitsTool(plot)) zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False) img_plot.overlays.append(zoom) #plot.y_axis.tick_label_formatter = lambda x: "%.3e" % x #plot.x_axis.tick_label_formatter = lambda x: "%.3e" % x #plot.tools.append(SaveTool(plot)) # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them my_plot = img_plot#plot.plots["my_plot"][0] colormap = my_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=my_plot, orientation='v', resizable='v', width=25, padding=0) colorbar.origin = 'bottom left' #colorbar._axis.tick_label_formatter = lambda x: '%.0e'%(x*10e6) + u' [\u00b5' + 'Watt]' colorbar._axis.tick_label_formatter = lambda x: ('%.0e'%(x*1e6)) colorbar._axis.orientation = 'right' colorbar._axis.title = u'Intensity [\u00b5W]' colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom colorbar.padding_right = 100 # 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.5, fill_color="lightgray")) range_selection.listeners.append(my_plot) imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) plot.overlays.append(ImageInspectorOverlay(component=img_plot, image_inspector=imgtool)) # we also want to the range selection to inform the cmap plot of # the selection, so set that up as well # 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 = "white" container.tools.append(SaveTool(container)) container.tools.append(TraitsTool(container)) #my_plot.set_value_selection((-1.3, 6.9)) return container