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))
Beispiel #2
0
    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
Beispiel #3
0
 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
Beispiel #4
0
    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
Beispiel #5
0
 def _plot_default(self):
     plot_data = ArrayPlotData(index=self.sigma, value=self.mu)
     self.plot_data = plot_data
     plot = Plot(data=plot_data)
     line = create_line_plot([self.sigma, self.mu],
                             add_grid=True,
                             value_bounds=(min(self.mean), max(self.mean)),
                             add_axis=True,
                             index_sort='ascending',
                             orientation='h')
     scatter = create_scatter_plot(
         [np.sqrt(np.diag(self.covar)),
          np.squeeze(self.mean)],
         index_bounds=(line.index_range.low, line.index_range.high),
         value_bounds=(line.value_range.low, line.value_range.high),
         marker='circle',
         color='blue')
     plot.add(line)
     left, bottom = line.underlays[-2:]
     left.title = 'Return'
     bottom.title = 'Risk'
     plot.add(scatter)
     cursor = CursorTool(line, drag_button='left', color='blue')
     self.cursor = cursor
     #cursor.current_position = self.sigma[0], self.mu[0]
     line.overlays.append(cursor)
     line.tools.append(PanTool(line, drag_button='right'))
     #line.overlays.append(ZoomTool(line))
     return plot
Beispiel #6
0
    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
Beispiel #8
0
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
Beispiel #9
0
    def create_plot_component(self):
        if not self.data.size:
            return

        self.pd = ArrayPlotData()
        self.shape = self.data.shape
        self.pd.set_data("imagedata", self.data)
        self.pd.set_data("left_line", self.data[:, self.shape[0]//2])
        self.pd.set_data("top_line", self.data[self.shape[1]//2,:])

        plot = Plot(self.pd)
        cmap = default_colormaps.color_map_name_dict[self.colormap]

        if self.rev_cmap:
            cmap = default_colormaps.reverse(cmap)

        drange = DataRange1D(ImageData(data=self.data, value_depth=1))



        self.ccmap = cmap_constant_range(cmap, drange)(drange)

            #from copy import copy
        self.img_plot = plot.img_plot("imagedata",
                                 colormap=cmap,
                                 #xbounds=self.xbounds,
                                 #ybounds=self.ybounds,
                                 )[0]
        self.cmap = self.img_plot.value_mapper
        if not self.autoscale:
            self.img_plot.value_mapper = self.ccmap
        # Tweak some of the plot properties
        plot.title = self.title
        plot.padding = 10

        # 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(self.img_plot,
                          drag_button='right',
                          color='white',
                          line_width=2.0
                          )
        self.cursor = csr

        csr.current_index = self.shape[0]//2, self.shape[1]//2
        self.img_plot.overlays.append(csr)

        imgtool = ImageInspectorTool(self.img_plot)
        self.img_plot.tools.append(imgtool)

        overlay = ImageInspectorOverlay(component=self.img_plot, image_inspector=imgtool,
                                        bgcolor="white", border_visible=True)

        self.img_plot.overlays.append(overlay)
        self.plot = plot

        self.cross_plot = Plot(self.pd,resizable='h')
        self.cross_plot.height = 40
        self.cross_plot.padding = 15
        self.cross_plot.plot("top_line",
                             line_style="dot")


        self.cross_plot.index_range = self.img_plot.index_range.x_range


        self.cross_plot2 = Plot(self.pd, width=40, orientation="v",
                                padding=15, padding_bottom=10, resizable='v')
        self.cross_plot2.plot("left_line",
                              line_style="dot")


        self.cross_plot2.index_range = self.img_plot.index_range.y_range

        # Create a container and add components
        #self.container = HPlotContainer(padding=10, fill_padding=False,
        #                                bgcolor="none", use_backbuffer=False)
        #inner_cont = VPlotContainer(padding=0, use_backbuffer=True, bgcolor="none")
        #inner_cont.add(self.plot)
        #inner_cont.add(self.cross_plot)
        self.container = GridPlotContainer(padding=20, fill_padding=False,
                                      bgcolor="none", use_backbuffer=True,
                                      shape=(2, 2), spacing=(12, 20))

        #self.container.add(self.colorbar)
        self.container.add(self.plot)
        self.container.add(self.cross_plot2)
        self.container.add(self.cross_plot)
Beispiel #10
0
    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
Beispiel #11
0
    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 __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