Exemplo n.º 1
0
    def __init__(self, **traits):
        super(HistDemo, self).__init__(**traits)
        img = cv.imread("lena.jpg")
        gray_img = cv.Mat()
        cv.cvtColor(img, gray_img, cv.CV_BGR2GRAY)
        self.img = gray_img
        self.img2 = self.img.clone()
        result = cv.MatND()

        r = cv.vector_float32([0, 256])
        ranges = cv.vector_vector_float32([r, r])

        cv.calcHist(cv.vector_Mat([self.img]),
                    channels=cv.vector_int([0, 1]),
                    mask=cv.Mat(),
                    hist=result,
                    histSize=cv.vector_int([256]),
                    ranges=ranges)

        data = ArrayPlotData(x=np.arange(0, len(result[:])), y=result[:])
        self.plot = Plot(data, padding=10)
        line = self.plot.plot(("x", "y"))[0]
        self.select_tool = RangeSelection(line, left_button_selects=True)
        line.tools.append(self.select_tool)
        self.select_tool.on_trait_change(self._selection_changed, "selection")
        line.overlays.append(RangeSelectionOverlay(component=line))

        cv.imshow("Hist Demo", self.img)

        self.timer = Timer(50, self.on_timer)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    def __init__(self, **traits):
        super(SelectionDemo, self).__init__(**traits)
        x = np.linspace(-140, 140, 1000)
        y = np.sin(x) * x**3
        y /= np.max(y)
        data = ArrayPlotData(x=x, y=y)

        self.plot1 = plot1 = Plot(data, padding=25)
        self.line1 = line1 = plot1.plot(("x", "y"), type="line")[0]

        self.select_tool = select_tool = RangeSelection(line1)
        line1.tools.append(select_tool)
        select_tool.on_trait_change(self._selection_changed, "selection")

        line1.overlays.append(RangeSelectionOverlay(component=line1))

        self.plot2 = plot2 = Plot(data, padding=25)
        plot2.plot(("x", "y"), type="line")[0]

        self.plot = VPlotContainer(plot2, plot1)

        self.data = data
Exemplo n.º 4
0
 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
Exemplo n.º 6
0
    def __init__(self):
        super(CyclesPlot, self).__init__()

        # Normally you'd pass in the data, but I'll hardwire things for this
        #    one-off plot.

        srecs = read_time_series_from_csv("./biz_cycles2.csv",
                                          date_col=0,
                                          date_format="%Y-%m-%d")

        dt = srecs["Date"]

        # Industrial production compared with trend (plotted on value axis)
        iprod_vs_trend = srecs["Metric 1"]

        # Industrial production change in last 6 Months (plotted on index axis)
        iprod_delta = srecs["Metric 2"]

        self._dates = dt
        self._series1 = self._selected_s1 = iprod_delta
        self._series2 = self._selected_s2 = iprod_vs_trend

        end_x = np.array([self._selected_s1[-1]])
        end_y = np.array([self._selected_s2[-1]])

        plotdata = ArrayPlotData(x=self._series1,
                                 y=self._series2,
                                 dates=self._dates,
                                 selected_x=self._selected_s1,
                                 selected_y=self._selected_s2,
                                 endpoint_x=end_x,
                                 endpoint_y=end_y)

        cycles = Plot(plotdata, padding=20)

        cycles.plot(("x", "y"), type="line", color=(.2, .4, .5, .4))

        cycles.plot(("selected_x", "selected_y"),
                    type="line",
                    marker="circle",
                    line_width=3,
                    color=(.2, .4, .5, .9))

        cycles.plot(("endpoint_x", "endpoint_y"),
                    type="scatter",
                    marker_size=4,
                    marker="circle",
                    color=(.2, .4, .5, .2),
                    outline_color=(.2, .4, .5, .6))

        cycles.index_range = DataRange1D(low_setting=80., high_setting=120.)

        cycles.value_range = DataRange1D(low_setting=80., high_setting=120.)

        # dig down to use actual Plot object
        cyc_plot = cycles.components[0]

        # Add the labels in the quadrants
        cyc_plot.overlays.append(
            PlotLabel("\nSlowdown" + 40 * " " + "Expansion",
                      component=cyc_plot,
                      font="swiss 24",
                      color=(.2, .4, .5, .6),
                      overlay_position="inside top"))

        cyc_plot.overlays.append(
            PlotLabel("Downturn" + 40 * " " + "Recovery\n ",
                      component=cyc_plot,
                      font="swiss 24",
                      color=(.2, .4, .5, .6),
                      overlay_position="inside bottom"))

        timeline = Plot(plotdata, resizable='h', height=50, padding=20)
        timeline.plot(("dates", "x"),
                      type="line",
                      color=(.2, .4, .5, .8),
                      name='x')
        timeline.plot(("dates", "y"),
                      type="line",
                      color=(.5, .4, .2, .8),
                      name='y')

        # Snap on the tools
        zoomer = ZoomTool(timeline,
                          drag_button="right",
                          always_on=True,
                          tool_mode="range",
                          axis="index",
                          max_zoom_out_factor=1.1)

        panner = PanTool(timeline, constrain=True, constrain_direction="x")

        # dig down to get Plot component I want
        x_plt = timeline.plots['x'][0]

        range_selection = RangeSelection(x_plt, left_button_selects=True)
        range_selection.on_trait_change(self.update_interval, 'selection')

        x_plt.tools.append(range_selection)
        x_plt.overlays.append(RangeSelectionOverlay(x_plt))

        # Set the plot's bottom axis to use the Scales ticking system
        scale_sys = CalendarScaleSystem(
            fill_ratio=0.4,
            default_numlabels=5,
            default_numticks=10,
        )
        tick_gen = ScalesTickGenerator(scale=scale_sys)

        bottom_axis = ScalesPlotAxis(timeline,
                                     orientation="bottom",
                                     tick_generator=tick_gen)

        # Hack to remove default axis - FIXME: how do I *replace* an axis?
        del (timeline.underlays[-2])

        timeline.overlays.append(bottom_axis)

        container = GridContainer(padding=20,
                                  fill_padding=True,
                                  bgcolor="lightgray",
                                  use_backbuffer=True,
                                  shape=(2, 1),
                                  spacing=(30, 30))

        # add a central "x" and "y" axis

        x_line = LineInspector(cyc_plot,
                               is_listener=True,
                               color="gray",
                               width=2)
        y_line = LineInspector(cyc_plot,
                               is_listener=True,
                               color="gray",
                               width=2,
                               axis="value")

        cyc_plot.overlays.append(x_line)
        cyc_plot.overlays.append(y_line)

        cyc_plot.index.metadata["selections"] = 100.0
        cyc_plot.value.metadata["selections"] = 100.0

        container.add(cycles)
        container.add(timeline)

        container.title = "Business Cycles"

        self.plot = container
Exemplo n.º 7
0
    def setup_plots(self):
        '''
        
        Args: 
        Returns:
        Raises:
        '''
        ext = self.extension

        if ext == "S2":
            color = "green"
        else:
            color = "blue"

        self.create_plot("AAE " + ext, ylabel="[ ]", color=color)
        self.create_plot("ARE " + ext, ylabel="[ ]", color=color)
        self.create_plot("Jerk " + ext, ylabel="[m/s2/s]", color=color)
        self.create_plot("SI " + ext, ylabel="[ ]", color=color)
        self.create_plot("VI " + ext, ylabel="[ ]", color=color)

        p = self.plots["VI " + ext]

        null_ds = ArrayDataSource([])
        self.time_plot = LinePlot(
            index=self.time_src,
            value=null_ds,
            index_mapper=LinearMapper(range=DataRange1D(self.time_src)),
            value_mapper=LinearMapper(range=DataRange1D(null_ds)),
            color="black",
            border_visible=True,
            bgcolor="white",
            height=10,
            resizable="h",
            padding_top=50,
            padding_bottom=40,
            padding_left=50,
            padding_right=20)
        self.ticker = ScalesTickGenerator()
        self.x_axis = LabelAxis(self.time_plot,
                                orientation="bottom",
                                title="Time [sec]",
                                label_rotation=0)
        #self.x_axis = PlotAxis(self.time_plot, orientation="bottom", tick_generator = self.ticker, title="Time [sec]")
        self.time_plot.underlays.append(self.x_axis)
        self.container.add(self.time_plot)

        # Add a range overlay to the miniplot that is hooked up to the range
        # of the main price_plot
        range_tool = RangeSelection(self.time_plot)
        self.time_plot.tools.append(range_tool)
        range_overlay = RangeSelectionOverlay(self.time_plot,
                                              metadata_name="selections")
        self.time_plot.overlays.append(range_overlay)
        range_tool.on_trait_change(self._range_selection_handler, "selection")
        self.range_tool = range_tool

        p.plot_conactory.index_range.on_trait_change(self._plot_range_handler,
                                                     "updated")
        self.zoom_overlay = ZoomOverlay(source=self.time_plot,
                                        destination=p.plot_conactory)
        self.container.overlays.append(self.zoom_overlay)