def __init__(self): # The delegates views don't work unless we caller the superclass __init__ super(CursorTest, self).__init__() container = HPlotContainer(padding=0, spacing=20) self.plot = container # a subcontainer for the first plot. # I'm not sure why this is required. Without it, the layout doesn't work right. subcontainer = OverlayPlotContainer(padding=40) container.add(subcontainer) # make some data index = numpy.linspace(-10, 10, 512) value = numpy.sin(index) # create a LinePlot instance and add it to the subcontainer line = create_line_plot([index, value], add_grid=True, add_axis=True, index_sort="ascending", orientation="h") subcontainer.add(line) # here's our first cursor. csr = CursorTool(line, drag_button="left", color="blue") self.cursor1 = csr # and set it's initial position (in data-space units) csr.current_position = 0.0, 0.0 # this is a rendered component so it goes in the overlays list line.overlays.append(csr) # some other standard tools line.tools.append(PanTool(line, drag_button="right")) line.overlays.append(ZoomTool(line)) # make some 2D data for a colourmap plot xy_range = (-5, 5) x = numpy.linspace(xy_range[0], xy_range[1], 100) y = numpy.linspace(xy_range[0], xy_range[1], 100) X, Y = numpy.meshgrid(x, y) Z = numpy.sin(X) * numpy.arctan2(Y, X) # easiest way to get a CMapImagePlot is to use the Plot class ds = ArrayPlotData() ds.set_data("img", Z) img = Plot(ds, padding=40) cmapImgPlot = img.img_plot("img", xbounds=xy_range, ybounds=xy_range, colormap=jet)[0] container.add(img) # now make another cursor csr2 = CursorTool(cmapImgPlot, drag_button="left", color="white", line_width=2.0) self.cursor2 = csr2 csr2.current_position = 1.0, 1.5 cmapImgPlot.overlays.append(csr2) # add some standard tools. Note, I'm assigning the PanTool to the # right mouse-button to avoid conflicting with the cursors cmapImgPlot.tools.append(PanTool(cmapImgPlot, drag_button="right")) cmapImgPlot.overlays.append(ZoomTool(cmapImgPlot))
def load(self, an): if an.peak_center_data: g = self.graph g.new_plot(xtitle='DAC', ytitle='Intensity') xs, ys = an.peak_center_data s, p = g.new_series(xs, ys) s.index.sort_order = 'ascending' t = CursorTool(s, drag_button="left", marker_size=5, color='darkgreen') s.overlays.append(t) dto = CursorToolOverlay( component=p, tool=t) p.overlays.append(dto) t.current_position = an.peak_center, 0 v = nominal_value(an.peak_center) g.add_vertical_rule(v) g.add_plot_label('Center={:0.5f} V'.format(v), font='modern 12', color='darkgreen') g.set_y_limits(pad='0.05', plotid=0) return True
def render_image(self): plot = super(CellCropper,self).render_image() img=plot.img_plot("imagedata", colormap=gray)[0] csr = CursorTool(img, drag_button='left', color='white', line_width=2.0) self.csr=csr csr.current_position=self.left, self.top img.overlays.append(csr) self.img_plot=plot return plot
def __init__(self, plot, pos_signal, drag_signal=None): super(CrossHair, self).__init__() self._pos_signal = pos_signal self._drag_signal = drag_signal csr = CursorTool(plot, drag_button='left', color='white', line_width=2.0, marker_size=2.0) self.cursor = csr csr.current_position = 0.0, 0.0 plot.overlays.append(csr) self.is_being_dragged = False
def render_image(self): plot = Plot(self.img_plotdata,default_origin="top left") img=plot.img_plot("imagedata", colormap=gray)[0] plot.title="%s of %s: "%(self.img_idx+1,self.numfiles)+self.titles[self.img_idx] plot.aspect_ratio=float(self.sig.data.shape[2])/float(self.sig.data.shape[1]) csr = CursorTool(img, drag_button='left', color='white', line_width=2.0) self.csr=csr csr.current_position=self.left, self.top img.overlays.append(csr) # attach the rectangle tool plot.tools.append(PanTool(plot,drag_button="right")) zoom = ZoomTool(plot, tool_mode="box", always_on=False, aspect_ratio=plot.aspect_ratio) plot.overlays.append(zoom) self.img_plot=plot return plot
def create_plot_component(self): # Create a scalar field to colormap # Create the plot if self.shape == self.zdata.shape: self.pd.set_data("imagedata", self.zdata) return self.pd = ArrayPlotData() self.shape = self.zdata.shape self.pd.set_data("imagedata", self.zdata) plot = Plot(self.pd) img_plot = plot.img_plot( "imagedata", colormap=jet, )[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='right', color='white', line_width=2.0) self.cursor = csr csr.current_position = self.shape[0] / 2, self.shape[ 1] / 2 #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) self.plot = plot
def _render_image(array_plot_data, title=None, tools=["zoom","pan"]): plot = Plot(array_plot_data, default_origin="top left") # the cursor tool, if any csr = None img_renderer = plot.img_plot("imagedata", colormap=gray, name="base_plot")[0] # todo: generalize title and aspect ratio plot.title = title data_array = array_plot_data.arrays['imagedata'] plot.aspect_ratio=float(data_array.shape[1]) / float(data_array.shape[0]) # attach the rectangle tool if "pan" in tools: plot.tools.append(PanTool(plot,drag_button="right")) if "zoom" in tools: zoom = ZoomTool(plot, tool_mode="box", always_on=False, aspect_ratio=plot.aspect_ratio) plot.overlays.append(zoom) if "csr" in tools: csr = CursorTool(img_renderer, drag_button='left', color='red', line_width=2.0) csr.current_position = 64, 64 img_renderer.overlays.append(csr) return plot, csr
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 __init__(self): #The delegates views don't work unless we caller the superclass __init__ super(CursorTest, self).__init__() container = HPlotContainer(padding=0, spacing=20) self.plot = container #a subcontainer for the first plot. #I'm not sure why this is required. Without it, the layout doesn't work right. subcontainer = OverlayPlotContainer(padding=40) container.add(subcontainer) #make some data index = numpy.linspace(-10, 10, 512) value = numpy.sin(index) #create a LinePlot instance and add it to the subcontainer line = create_line_plot([index, value], add_grid=True, add_axis=True, index_sort='ascending', orientation='h') subcontainer.add(line) #here's our first cursor. csr = CursorTool(line, drag_button="left", color='blue') self.cursor1 = csr #and set it's initial position (in data-space units) csr.current_position = 0.0, 0.0 #this is a rendered component so it goes in the overlays list line.overlays.append(csr) #some other standard tools line.tools.append(PanTool(line, drag_button="right")) line.overlays.append(ZoomTool(line)) #make some 2D data for a colourmap plot xy_range = (-5, 5) x = numpy.linspace(xy_range[0], xy_range[1], 100) y = numpy.linspace(xy_range[0], xy_range[1], 100) X, Y = numpy.meshgrid(x, y) Z = numpy.sin(X) * numpy.arctan2(Y, X) #easiest way to get a CMapImagePlot is to use the Plot class ds = ArrayPlotData() ds.set_data('img', Z) img = Plot(ds, padding=40) cmapImgPlot = img.img_plot("img", xbounds=xy_range, ybounds=xy_range, colormap=jet)[0] container.add(img) #now make another cursor csr2 = CursorTool(cmapImgPlot, drag_button='left', color='white', line_width=2.0) self.cursor2 = csr2 csr2.current_position = 1.0, 1.5 cmapImgPlot.overlays.append(csr2) #add some standard tools. Note, I'm assigning the PanTool to the #right mouse-button to avoid conflicting with the cursors cmapImgPlot.tools.append(PanTool(cmapImgPlot, drag_button="right")) cmapImgPlot.overlays.append(ZoomTool(cmapImgPlot))