Beispiel #1
0
    def _ch_plot_default(self):
        x = 0.26
        y = 0.
        h_cross_x = np.array([self.x_low, self.x_high])
        h_cross_y = np.array([y, y])
        v_cross_x = np.array([x, x])
        v_cross_y = np.array([self.y_low, self.y_high])

        cross_hair_data = ArrayPlotData(h_cross_x=h_cross_x,
                                        h_cross_y=h_cross_y,
                                        v_cross_x=v_cross_x,
                                        v_cross_y=v_cross_y)
        ch_plot = Plot(cross_hair_data)
        ch_plot.plot(("h_cross_x", "h_cross_y"), type="line", color="green",)
        ch_plot.plot(("v_cross_x", "v_cross_y"), type="line", color="green",)
        while len(ch_plot.underlays) > 0:
            ch_plot.underlays.pop(0)
        ch_plot.range2d = self.img_plot.range2d
        cross_hair_tool = CrossHairs(ch_plot)
        ch_plot.tools.append(cross_hair_tool)
        self.crosshair = cross_hair_tool
        self.on_trait_change(self.draw_cross_hairs,
                             "crosshair.selected_x, crosshair.selected_y")
        self.on_trait_change(self.render_julia,
                             "crosshair.selected_x, crosshair.selected_y")
        return ch_plot
Beispiel #2
0
    def _container_default(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        # Create the line plot, rotated and vertically oriented
        line = Plot(plotdata, orientation="v", default_origin="top left")
        line.plot(("x", "y"), type="line", color="blue")

        # Add pan/zoom so we can see they are connected
        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))
        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        # Set the two plots' ranges to be the same
        scatter.range2d = line.range2d

        # Create a horizontal container and put the two plots inside it
        return HPlotContainer(scatter, line)
Beispiel #3
0
    def __init__(self):
        super(ConnectedRange, self).__init__()
        x = linspace(-14, 14, 100)
        y = sin(x) * x ** 3
        plotdata = ArrayPlotData(x=x, y=y)

        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        line = Plot(plotdata)
        #line = Plot(plotdata, orientation="v", default_origin="top left")
        line.plot(("x", "y"), type="line", color="red")

        self.container = HPlotContainer(scatter, line)

        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))

        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        #Axis link options, try them out
        #scatter.value_range = line.value_range  # Link y-axis only
        #scatter.index_range = line.index_range  # Link x-axis only
        scatter.range2d = line.range2d  # Link both axes
Beispiel #4
0
    def __init__(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        # Create the line plot
        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")

        # Create a horizontal container and put the two plots inside it
        self.container = HPlotContainer(scatter, line)

        # Add pan/zoom so we can see they are connected
        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))
        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        # Set the two plots' ranges to be the same
        scatter.range2d = line.range2d
Beispiel #5
0
    def __init__(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x ** 3
        plotdata = ArrayPlotData(x=x, y=y)

        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        # Create the line plot, rotated and vertically oriented
        line = Plot(plotdata, orientation="v", default_origin="top left")
        line.plot(("x", "y"), type="line", color="blue")

        # Create a horizontal container and put the two plots inside it
        self.container = HPlotContainer(scatter, line)

        # Add pan/zoom so we can see they are connected
        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))
        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        # Set the two plots' ranges to be the same
        scatter.range2d = line.range2d
    def _container_default(self):
        x = linspace(-10, 10, 100)
        y = sin(x) * x
        plotdata = ArrayPlotData(x=x, y=y)

        scatter = Plot(plotdata)
        scatter.plot(('x', 'y'), type='scatter', color='blue')

        line = Plot(plotdata)
        line.plot(('x', 'y'), type='line', color='green')

        container = HPlotContainer(scatter, line)

        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))

        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        # Chaco has the concept of data range to express bounds in data space
        # Standard 2D plots all have 2D ranges on them
        # Here two plots now share same range object, and will change together
        # In response to changes to the data space bounds.
        scatter.range2d = line.range2d
        return container
    def _container_default(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x = x, y = y)
        
        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")
        
        # Create the line plot
        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")
        
        # Add pan/zoom so we can see they are connected
        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))
        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))
        
        # Set the two plots' ranges to be the same
        scatter.range2d = line.range2d

        # Create a horizontal container and put the two plots inside it
        return HPlotContainer(scatter, line)
Beispiel #8
0
def _render_scatter_overlay(base_plot, array_plot_data,
                            marker="circle", fill_alpha=0.5,
                            marker_size=6, tools=[]):
    #if 'index' not in array_plot_data.arrays:
        #return base_plot, None
    
    scatter_plot = Plot(array_plot_data, aspect_ratio = base_plot.aspect_ratio, 
                default_origin="top left")
    
    if "color" in array_plot_data.arrays:
        scatter_plot.plot(("index", "value", "color"),
                      type="cmap_scatter",
                      name="scatter_plot",
                      color_mapper=jet,
                      marker = marker,
                      fill_alpha = fill_alpha,
                      marker_size = marker_size,
                      )
        scatter_renderer = scatter_plot.plots['scatter_plot'][0]
        colorbar = _create_colorbar(scatter_plot.color_mapper, tools=tools)
        colorbar.plot = scatter_renderer
        #colorbar.padding_top = scatter_renderer.padding_top
        #colorbar.padding_bottom = scatter_renderer.padding_bottom
        if 'colorbar' in tools:
            # this part is for making the colormapped points fade when they
            #  are not selected by the threshold.
            # The renderer is the actual class that does the rendering - 
            # the Plot class calls this other class.  When we say 
            #   plots['scatter_plot']
            # we are getting the named plot that we created above.
            # The extra [0] on the end is because we get a list - in case
            # there is more than one plot named "scatter_plot"
            selection = ColormappedSelectionOverlay(scatter_renderer, 
                                                    fade_alpha=0.35, 
                                                    selection_type="range")
            scatter_renderer.overlays.append(selection)
    else:
        colorbar = None
    if 'inspector' in tools:
        # Attach the inspector and its overlay
        scatter_renderer = scatter_plot.plots['scatter_plot'][0]
        #scatter_plot.tools.append(PeakSelectionTool(scatter_renderer))
        selection = ColormappedSelectionOverlay(scatter_renderer, 
                                                fade_alpha=0.35, 
                                                selection_type="mask")
        scatter_plot.overlays.append(selection)
    scatter_plot.x_grid.visible = False
    scatter_plot.y_grid.visible = False
    scatter_plot.range2d = base_plot.range2d
    return scatter_plot, colorbar
Beispiel #9
0
def _render_quiver_overlay(base_plot, array_plot_data, 
                           line_color="white", line_width=1.0, 
                           arrow_size=5):
    if 'vectors' not in array_plot_data.arrays:
        return base_plot
    quiverplot = Plot(array_plot_data, aspect_ratio = base_plot.aspect_ratio, 
                default_origin="top left")
    quiverplot.quiverplot(("index", "value", "vectors"), name="quiver_plot",
                    line_color=line_color, line_width=line_width, 
                    arrow_size=arrow_size)
    quiverplot.x_grid.visible = False
    quiverplot.y_grid.visible = False
    quiverplot.range2d = base_plot.range2d
    return quiverplot
Beispiel #10
0
 def render_scatplot(self):
     peakdata=ArrayPlotData()
     peakdata.set_data("index",self.peaks[self.img_idx][:,0])
     peakdata.set_data("value",self.peaks[self.img_idx][:,1])
     peakdata.set_data("color",self.peaks[self.img_idx][:,2])
     scatplot=Plot(peakdata,aspect_ratio=self.img_plot.aspect_ratio,default_origin="top left")
     scatplot.plot(("index", "value", "color"),
                   type="cmap_scatter",
                   name="my_plot",
                   color_mapper=jet(DataRange1D(low = 0.0,
                                    high = 1.0)),
                   marker = "circle",
                   fill_alpha = 0.5,
                   marker_size = 6,
                   )
     scatplot.x_grid.visible = False
     scatplot.y_grid.visible = False
     scatplot.range2d=self.img_plot.range2d
     self.scatplot=scatplot
     self.peakdata=peakdata
     return scatplot
Beispiel #11
0
    def _plot_default(self):
        distr_len = len(self.data)

        # PolygonPlot holding the circles of the Hinton diagram
        polyplot = Plot(self.plot_data)
        for idx in range(distr_len):
            p = polyplot.plot(('x%d' % idx, 'y%d' % idx),
                              type="polygon",
                              face_color=get_class_color(idx),
                              edge_color='black')

        self._set_title(polyplot)
        self._remove_grid_and_axes(polyplot)

        # create x axis for labels
        axis = self._create_increment_one_axis(polyplot, 1., distr_len,
                                               'bottom')
        self._add_index_axis(polyplot, axis)

        # create y axis for probability density
        #prob_axis = self._create_probability_axis(polyplot)
        #polyplot.value_axis = prob_axis
        #polyplot.underlays.append(prob_axis)

        # tweak some of the plot properties
        range2d = DataRange2D(low=(0.5, 0.), high=(distr_len + 0.5, 1.))
        polyplot.range2d = range2d
        polyplot.aspect_ratio = ((range2d.x_range.high - range2d.x_range.low) /
                                 (range2d.y_range.high - range2d.y_range.low))

        polyplot.border_visible = False
        polyplot.padding = [0, 0, 25, 25]

        # create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, valign='center')
        container.add(polyplot)
        container.bgcolor = 0xFFFFFF  # light gray: 0xEEEEEE

        self.decorate_plot(container, self.data)
        return container
Beispiel #12
0
    def _plot_default(self):
        distr_len = len(self.data)

        # PolygonPlot holding the circles of the Hinton diagram
        polyplot = Plot(self.plot_data)
        for idx in range(distr_len):
            p = polyplot.plot(('x%d' % idx, 'y%d' % idx),
                          type="polygon",
                          face_color=get_class_color(idx),
                          edge_color='black')

        self._set_title(polyplot)
        self._remove_grid_and_axes(polyplot)

        # create x axis for labels
        axis = self._create_increment_one_axis(polyplot, 1., distr_len, 'bottom')
        self._add_index_axis(polyplot, axis)

        # create y axis for probability density
        #prob_axis = self._create_probability_axis(polyplot)
        #polyplot.value_axis = prob_axis
        #polyplot.underlays.append(prob_axis)

        # tweak some of the plot properties
        range2d = DataRange2D(low=(0.5, 0.), high=(distr_len+0.5, 1.))
        polyplot.range2d = range2d
        polyplot.aspect_ratio = ((range2d.x_range.high - range2d.x_range.low)
                                 / (range2d.y_range.high - range2d.y_range.low))

        polyplot.border_visible = False
        polyplot.padding = [0, 0, 25, 25]

        # create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, valign='center')
        container.add(polyplot)
        container.bgcolor = 0xFFFFFF # light gray: 0xEEEEEE

        self.decorate_plot(container, self.data)
        return container
Beispiel #13
0
    def _brain_default(self):
        plot = Plot(self.brain_data, padding=0)
        plot.width = self.brain_voxels.shape[1]
        plot.height = self.brain_voxels.shape[0]
        plot.aspect_ratio = 1.
        plot.index_axis.visible = False
        plot.value_axis.visible = False
        renderer = plot.img_plot("axial", colormap=gray)[0]
        plot.color_mapper.range = DataRange1D(low=0., high=1.0)
        plot.bgcolor = 'pink'

        # Brain tools
        plot.tools.append(PanTool(plot, drag_button="right"))
        plot.tools.append(ZoomTool(plot))
        imgtool = ImageInspectorTool(renderer)
        renderer.tools.append(imgtool)
        overlay = ImageInspectorOverlay(component=renderer, image_inspector=imgtool,
                                        bgcolor="white", border_visible=True)
        renderer.overlays.append(overlay)

        # Brain track cursor
        self.cursor = CursorTool2D(renderer, drag_button='left', color='red', line_width=2.0)
        #self.cursor.on_trait_change(self.update_stackedhist, 'current_index')
        self.cursor.current_positionyou = (0., 0.)
        renderer.overlays.append(self.cursor)

        # Brain colorbar
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=20,
                            padding=(30, 0, 0, 0))
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        # Noisy brain
        plot2 = Plot(self.brain_data, padding=0)
        plot2.width = self.brain_voxels.shape[1]
        plot2.height = self.brain_voxels.shape[0]
        plot2.aspect_ratio = 1.
        plot2.index_axis.visible = False
        plot2.value_axis.visible = False
        renderer2 = plot2.img_plot("noisy_axial", colormap=gray)[0]
        plot2.color_mapper.range = DataRange1D(low=0., high=1.0)
        plot2.bgcolor = 'pink'
        plot2.range2d = plot.range2d

        # Brain_map tools
        plot2.tools.append(PanTool(plot2, drag_button="right"))
        plot2.tools.append(ZoomTool(plot2))
        imgtool2 = ImageInspectorTool(renderer2)
        renderer2.tools.append(imgtool2)
        overlay2 = ImageInspectorOverlay(component=renderer2, image_inspector=imgtool2,
                                         bgcolor="white", border_visible=True)
        renderer2.overlays.append(overlay2)

        # Brain_map track cursor
        self.cursor2 = CursorTool2D(renderer2, drag_button='left', color='red', line_width=2.0)
        #self.cursor2.on_trait_change(self.cursor2_changed, 'current_index')
        self.cursor2.current_position = (0., 0.)
        renderer2.overlays.append(self.cursor2)

        # Brain_map colorbar
        colormap2 = plot2.color_mapper
        colorbar2 = ColorBar(index_mapper=LinearMapper(range=colormap2.range),
                             color_mapper=colormap2,
                             plot=plot2,
                             orientation='v',
                             resizable='v',
                             width=20,
                             padding=(30, 0, 0, 0))
        colorbar2.padding_top = plot2.padding_top
        colorbar2.padding_bottom = plot2.padding_bottom

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10))
        container.add(plot)
        container.add(colorbar)
        container.bgcolor = "lightgray"

        container2 = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10))
        container2.add(plot2)
        container2.add(colorbar2)
        container2.bgcolor = "lightgray"

        Hcontainer = HPlotContainer(use_backbuffer=True)
        Hcontainer.add(container)
        Hcontainer.add(container2)
        Hcontainer.bgcolor = "lightgray"

        return Hcontainer
Beispiel #14
0
    def _create_plot(self):

        # count data
        if len(self.df) > 0:
            self.indexes = np.arange(len(self.df.date_time))
            time_ds = ArrayDataSource(self.indexes)
            vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none")
            xmapper = LinearMapper(range=DataRange1D(time_ds))
            vol_mapper = LinearMapper(range=DataRange1D(vol_ds))

            ####################################################################
            # create volumn plot
            vol_plot = BarPlot(index=time_ds, value=vol_ds,
                               index_mapper=xmapper,
                               value_mapper=vol_mapper,
                               line_color="transparent",
                               fill_color="blue",
                               bar_width=0.6,
                               antialias=False,
                               height=100,
                               resizable="h",
                               origin="bottom left",
                               bgcolor="white",
                               border_visible=True
                               )

            vol_plot.padding = 30
            vol_plot.padding_left = 40
            vol_plot.tools.append(
                PanTool(vol_plot, constrain=True, constrain_direction="x"))
            add_default_grids(vol_plot)
            add_default_axes(vol_plot)

            #print vol_plot.index_mapper.range.high
            #print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high
            self.vol_plot = vol_plot
            self.container.add(vol_plot)

            ####################################################################
            ## Create price plot

            sorted_vals = np.vstack(
                (self.df.open, self.df.high, self.df.low, self.df.close))
            sorted_vals.sort(0)
            __bool = self.df.close.values - self.df.open.values
            self.up_boolean = __bool >= 0
            self.down_boolean = np.invert(self.up_boolean)

            pd = ArrayPlotData(
                up_index=self.indexes[self.up_boolean],
                up_min=sorted_vals[0][self.up_boolean],
                up_bar_min=sorted_vals[1][self.up_boolean],
                up_bar_max=sorted_vals[2][self.up_boolean],
                up_max=sorted_vals[3][self.up_boolean],
                down_index=self.indexes[self.down_boolean],
                down_min=sorted_vals[0][self.down_boolean],
                down_bar_min=sorted_vals[1][self.down_boolean],
                down_bar_max=sorted_vals[2][self.down_boolean],
                down_max=sorted_vals[3][self.down_boolean],
                volumn=self.df.volumn.values,
                index=self.indexes
            )

            price_plot = Plot(pd)

            up_plot = price_plot.candle_plot(
                ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"),
                color=color_red,
                bgcolor="azure",
                bar_line_color="black",
                stem_color="black",
                end_cap=False)[0]

            down_plot = price_plot.candle_plot(
                ("down_index", "down_min", "down_bar_min",
                 "down_bar_max", "down_max"),
                color=color_green,
                bar_line_color="black",
                stem_color="black",
                end_cap=False)[0]

            price_plot.fill_padding = True
            price_plot.padding = 30
            price_plot.padding_left = 40

            price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False))
            price_plot.tools.append(PanTool(price_plot, drag_button="left"))
            price_plot.tools.append(
                XYTool(price_plot, callback=self._update_ohlc))  # get data
            self._add_line_tool(up_plot)
            self._add_line_tool(down_plot)
            price_plot.range2d = self._compute_range2d()

            price_plot.index_mapper = vol_plot.index_mapper  # maper vol_plot and price_plot
            self.price_plot = price_plot

            self.container.add(price_plot)
Beispiel #15
0
    def _create_plot(self):

        # count data
        if len(self.df) > 0:
            self.indexes = np.arange(len(self.df.date_time))
            time_ds = ArrayDataSource(self.indexes)
            vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none")
            xmapper = LinearMapper(range=DataRange1D(time_ds))
            vol_mapper = LinearMapper(range=DataRange1D(vol_ds))

            ####################################################################
            # create volumn plot
            vol_plot = BarPlot(
                index=time_ds,
                value=vol_ds,
                index_mapper=xmapper,
                value_mapper=vol_mapper,
                line_color="transparent",
                fill_color="blue",
                bar_width=0.6,
                antialias=False,
                height=100,
                resizable="h",
                origin="bottom left",
                bgcolor="white",
                border_visible=True,
            )

            vol_plot.padding = 30
            vol_plot.padding_left = 40
            vol_plot.tools.append(PanTool(vol_plot, constrain=True, constrain_direction="x"))
            add_default_grids(vol_plot)
            add_default_axes(vol_plot)

            # print vol_plot.index_mapper.range.high
            # print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high
            self.vol_plot = vol_plot
            self.container.add(vol_plot)

            ####################################################################
            ## Create price plot

            sorted_vals = np.vstack((self.df.open, self.df.high, self.df.low, self.df.close))
            sorted_vals.sort(0)
            __bool = self.df.close.values - self.df.open.values
            self.up_boolean = __bool >= 0
            self.down_boolean = np.invert(self.up_boolean)

            pd = ArrayPlotData(
                up_index=self.indexes[self.up_boolean],
                up_min=sorted_vals[0][self.up_boolean],
                up_bar_min=sorted_vals[1][self.up_boolean],
                up_bar_max=sorted_vals[2][self.up_boolean],
                up_max=sorted_vals[3][self.up_boolean],
                down_index=self.indexes[self.down_boolean],
                down_min=sorted_vals[0][self.down_boolean],
                down_bar_min=sorted_vals[1][self.down_boolean],
                down_bar_max=sorted_vals[2][self.down_boolean],
                down_max=sorted_vals[3][self.down_boolean],
                volumn=self.df.volumn.values,
                index=self.indexes,
            )

            price_plot = Plot(pd)

            up_plot = price_plot.candle_plot(
                ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"),
                color=color_red,
                bgcolor="azure",
                bar_line_color="black",
                stem_color="black",
                end_cap=False,
            )[0]

            down_plot = price_plot.candle_plot(
                ("down_index", "down_min", "down_bar_min", "down_bar_max", "down_max"),
                color=color_green,
                bar_line_color="black",
                stem_color="black",
                end_cap=False,
            )[0]

            price_plot.fill_padding = True
            price_plot.padding = 30
            price_plot.padding_left = 40

            price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False))
            price_plot.tools.append(PanTool(price_plot, drag_button="left"))
            price_plot.tools.append(XYTool(price_plot, callback=self._update_ohlc))  # get data
            self._add_line_tool(up_plot)
            self._add_line_tool(down_plot)
            price_plot.range2d = self._compute_range2d()

            price_plot.index_mapper = vol_plot.index_mapper  # maper vol_plot and price_plot
            self.price_plot = price_plot

            self.container.add(price_plot)