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 __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
Exemple #3
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)
Exemple #4
0
    def attach_tools(self):
        """ attach_tools(self) contains the relevant tools: clicker, pan, zoom
        """
        pan = PanTool(self._plot, drag_button='middle')
        zoom_tool = ZoomTool(self._plot, tool_mode="box", always_on=False)
#       zoom_tool = BetterZoom(component=self._plot, tool_mode="box", always_on=False)
        zoom_tool.max_zoom_out_factor = 1.0  # Disable "bird view" zoom out
        self._img_plot.overlays.append(zoom_tool)
        self._img_plot.tools.append(pan)
Exemple #5
0
 def attach_tools(self):
     """ attach_tools(self) contains the relevant tools: clicker, pan, zoom
     """
     pan = PanTool(self._plot, drag_button='middle')
     zoom_tool = ZoomTool(self._plot, tool_mode="box", always_on=False)
     #       zoom_tool = BetterZoom(component=self._plot, tool_mode="box", always_on=False)
     zoom_tool.max_zoom_out_factor = 1.0  # Disable "bird view" zoom out
     self._img_plot.overlays.append(zoom_tool)
     self._img_plot.tools.append(pan)
Exemple #6
0
def _create_plot_component():

    # Create the index
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high, (high - low) / numpoints)
    plotdata = ArrayPlotData(x=x, y1=jn(0, x), y2=jn(1, x))

    # Create the left plot
    left_plot = Plot(plotdata)
    left_plot.x_axis.title = "X"
    left_plot.y_axis.title = "j0(x)"
    renderer = left_plot.plot(("x", "y1"),
                              type="line",
                              color="blue",
                              width=2.0)[0]
    renderer.overlays.append(
        LineInspector(renderer,
                      axis='value',
                      write_metadata=True,
                      is_listener=True))
    renderer.overlays.append(
        LineInspector(renderer,
                      axis="index",
                      write_metadata=True,
                      is_listener=True))
    left_plot.overlays.append(ZoomTool(left_plot, tool_mode="range"))
    left_plot.tools.append(PanTool(left_plot))

    # Create the right plot
    right_plot = Plot(plotdata)
    right_plot.index_range = left_plot.index_range
    right_plot.orientation = "v"
    right_plot.x_axis.title = "j1(x)"
    right_plot.y_axis.title = "X"
    renderer2 = right_plot.plot(("x", "y2"),
                                type="line",
                                color="red",
                                width=2.0)[0]
    renderer2.index = renderer.index
    renderer2.overlays.append(
        LineInspector(renderer2, write_metadata=True, is_listener=True))
    renderer2.overlays.append(
        LineInspector(renderer2, axis="value", is_listener=True))
    right_plot.overlays.append(ZoomTool(right_plot, tool_mode="range"))
    right_plot.tools.append(PanTool(right_plot))

    container = HPlotContainer(background="lightgray")
    container.add(left_plot)
    container.add(right_plot)

    return container
Exemple #7
0
    def _container_default(self):
        container = super(PlotExample2, self)._container_default()

        rplot, lplot = self.right_plot, self.left_plot
        rplot.index_mapper.range = lplot.index_mapper.range
        rplot.value_mapper.range = lplot.value_mapper.range

        lplot.overlays.append(ZoomTool(lplot, tool_mode="box",
                                       always_on=False))
        rplot.overlays.append(ZoomTool(rplot, tool_mode="box",
                                       always_on=False))

        return container
Exemple #8
0
 def attach_tools(self):
     """ attach_tools(self) contains the relevant tools: clicker, pan, zoom
     """
     self._click_tool = Clicker(self._img_plot)
     self._click_tool.on_trait_change(self.left_clicked_event, 'left_changed')  # set processing events for Clicker
     self._click_tool.on_trait_change(self.right_clicked_event, 'right_changed')
     self._img_plot.tools.append(self._click_tool)
     pan = PanTool(self._plot, drag_button='middle')
     zoom_tool = ZoomTool(self._plot, tool_mode="box", always_on=False)
     #       zoom_tool = BetterZoom(component=self._plot, tool_mode="box", always_on=False)
     zoom_tool.max_zoom_out_factor = 1.0  # Disable "bird view" zoom out
     self._img_plot.overlays.append(zoom_tool)
     self._img_plot.tools.append(pan)
Exemple #9
0
	def attach_tools(self):
		""" attach_tools(self) contains the relevant tools: clicker, pan, zoom
		"""
		self._click_tool=Clicker(self._img_plot)
		self._click_tool.on_trait_change(self.left_clicked_event, 'left_changed') #set processing events for Clicker
		self._click_tool.on_trait_change(self.right_clicked_event, 'right_changed')
		self._img_plot.tools.append(self._click_tool)
		pan = PanTool(self._plot, drag_button = 'middle')
		zoom_tool= ZoomTool(self._plot, tool_mode="box", always_on=False)
#		zoom_tool = BetterZoom(component=self._plot, tool_mode="box", always_on=False)
		zoom_tool.max_zoom_out_factor=1.0 # Disable "bird view" zoom out
		self._img_plot.overlays.append(zoom_tool)
		self._img_plot.tools.append(pan)
Exemple #10
0
    def _plot_default(self):
        # Create a GridContainer to hold all of our plots: 2 rows, 4 columns:
        container = GridContainer(fill_padding=True,
                                  bgcolor="lightgray", use_backbuffer=True,
                                  shape=(2, 4))

        arrangements = [('top left', 'h'),
                        ('top right', 'h'),
                        ('top left', 'v'),
                        ('top right', 'v'),
                        ('bottom left', 'h'),
                        ('bottom right', 'h'),
                        ('bottom left', 'v'),
                        ('bottom right', 'v')]
        orientation_name = {'h': 'horizontal', 'v': 'vertical'}

        pd = ArrayPlotData(image=lena())
        # Plot some bessel functions and add the plots to our container
        for origin, orientation in arrangements:
            plot = Plot(pd, default_origin=origin, orientation=orientation)
            plot.img_plot('image')

            # Attach some tools to the plot
            plot.tools.append(PanTool(plot))
            zoom = ZoomTool(plot, tool_mode="box", always_on=False)
            plot.overlays.append(zoom)

            title = '{0}, {1}'
            plot.title = title.format(orientation_name[orientation],
                                      origin.replace(' ', '-'))

            # Add to the grid container
            container.add(plot)

        return container
Exemple #11
0
    def _add_plot_tools(self, imgplot, token):
        """ Add LineInspectors, ImageIndexTool, and ZoomTool to the image plots. """

        imgplot.overlays.append(
            ZoomTool(component=imgplot,
                     tool_mode="box",
                     enable_wheel=False,
                     always_on=False))
        imgplot.overlays.append(
            LineInspector(imgplot,
                          axis="index_y",
                          color="white",
                          inspect_mode="indexed",
                          write_metadata=True,
                          is_listener=True))
        imgplot.overlays.append(
            LineInspector(imgplot,
                          axis="index_x",
                          color="white",
                          inspect_mode="indexed",
                          write_metadata=True,
                          is_listener=True))
        imgplot.tools.append(
            ImageIndexTool(imgplot,
                           token=token,
                           callback=self._index_callback,
                           wheel_cb=self._wheel_callback))
Exemple #12
0
def _create_plot_component():

    # Create some data
    index, sorted_vals = _create_data(200)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData(index = index,
                       min = sorted_vals[0],
                       bar_min = sorted_vals[1],
                       average = sorted_vals[2],
                       bar_max = sorted_vals[3],
                       max = sorted_vals[4])

    # Create the plot
    plot = Plot(pd)
    plot.candle_plot(("index", "min", "bar_min", "average", "bar_max", "max"),
                     color = "lightgray",
                     bar_line_color = "black",
                     stem_color = "blue",
                     center_color = "red",
                     center_width = 2)

    # Tweak some of the plot properties
    plot.title = "Candlestick Plot"
    plot.line_width = 0.5
    plot.padding = 50

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)

    return plot
Exemple #13
0
    def _create_window(self):
        self._create_data()
        x = self.x_values[:self.current_index]
        y = self.y_values[:self.current_index]

        value_range = None
        index_range = None
        plot = create_line_plot((x, y), color="red", width=2.0)
        value_range = plot.value_mapper.range
        index_range = plot.index_mapper.range
        index_range.low = -5
        index_range.high = 15
        plot.padding = 50
        plot.fill_padding = True
        plot.bgcolor = "white"
        left, bottom = add_default_axes(plot)
        hgrid, vgrid = add_default_grids(plot)
        bottom.tick_interval = 2.0
        vgrid.grid_interval = 2.0

        self.plot = plot
        plot.tools.append(PanTool(component=plot))
        plot.overlays.append(
            ZoomTool(component=plot, tool_mode="box", always_on=False))

        # Set the timer to generate events to us
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
        self.timer.Start(50.0, wx.TIMER_CONTINUOUS)
        return Window(self, -1, component=plot)
def _create_plot_component():
    pd = ArrayPlotData(x=random(100), y=random(100))

    # Create some line plots of some of the data
    plot = Plot(pd)

    # Create a scatter plot and get a reference to it (separate from the
    # Plot object) because we'll need it for the regression tool below.
    scatterplot = plot.plot(("x", "y"), color="blue", type="scatter")[0]

    # Tweak some of the plot properties
    plot.padding = 50

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot, drag_button="right"))
    plot.overlays.append(ZoomTool(plot))

    # Add the regression tool and overlay.  These need to be added
    # directly to the scatterplot instance (and not the Plot instance).
    regression = RegressionLasso(scatterplot,
                                 selection_datasource=scatterplot.index)
    scatterplot.tools.append(regression)
    scatterplot.overlays.append(
        RegressionOverlay(scatterplot, lasso_selection=regression))
    return plot
Exemple #15
0
    def _setup_plot_tools(self, plot):
        """Sets up the background, and several tools on a plot"""
        # Make a white background with grids and axes
        plot.bgcolor = "white"
        add_default_grids(plot)
        add_default_axes(plot)

        # Allow white space around plot
        plot.index_range.tight_bounds = False
        plot.index_range.refresh()
        plot.value_range.tight_bounds = False
        plot.value_range.refresh()

        # The PanTool allows panning around the plot
        plot.tools.append(PanTool(plot))

        # The ZoomTool tool is stateful and allows drawing a zoom
        # box to select a zoom region.
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # The DragZoom tool just zooms in and out as the user drags
        # the mouse vertically.
        dragzoom = DragZoom(plot, drag_button="right")
        plot.tools.append(dragzoom)

        # Add a legend in the upper right corner, and make it relocatable
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        plot.overlays.append(legend)

        return plot.value_mapper, plot.index_mapper, legend
def _create_plot_component():

    # Create some data
    numpts = 1000
    x = sort(random(numpts))
    y = random(numpts)
    color = randint(0, 7, numpts)

    # 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=accent,
              marker="square",
              fill_alpha=0.5,
              marker_size=6,
              outline_color="black",
              border_visible=True,
              bgcolor="white")

    # Tweak some of the plot properties
    plot.title = "Colormapped Scatter Plot with Range-selectable Data Points"
    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"

    # Right now, some of the tools are a little invasive, and we need the
    # actual ColomappedScatterPlot object to give to them
    cmap_renderer = plot.plots["my_plot"][0]

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)
    selection = ColormappedSelectionOverlay(cmap_renderer,
                                            fade_alpha=0.35,
                                            selection_type="mask")
    cmap_renderer.overlays.append(selection)

    # Create the colorbar, handing in the appropriate range and colormap
    colorbar = create_colorbar(plot.color_mapper)
    colorbar.plot = cmap_renderer
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # 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"
    return container
Exemple #17
0
    def _add_line_plots(self, plot):
        """Adds curve line plots to the ChacoPlot"""

        line_plots = []
        for plot_config in self.line_plot_configs:
            line_plot = ChacoPlot(self._plot_data)

            # Customize text
            line_plot.trait_set(title=plot_config.title,
                                padding=75,
                                line_width=1)
            line_plot.x_axis.title = plot_config.x_label
            line_plot.y_axis.title = plot_config.y_label

            # Add pan and zoom tools
            line_plot.tools.append(PanTool(line_plot))
            line_plot.overlays.append(ZoomTool(line_plot))

            for name, kwargs in plot_config.line_config.items():
                line = line_plot.plot((f"x_line_{name}", f"y_line_{name}"),
                                      type="line",
                                      **kwargs)[0]
                self._sub_axes[f'{name}_line_plot'] = line

            line_plots.append(line_plot)

        container = GridPlotContainer(*line_plots,
                                      shape=self._grid_shape,
                                      spacing=(0, 0),
                                      valign='top',
                                      bgcolor="none")
        self._component = HPlotContainer(plot, container, bgcolor="none")
        self._line_plots = line_plots
    def _time_plot_default(self):
        time_plot = Plot(self.time_plot_data)

        time_plot.plot(('t', 'y'))

        time_plot.index_axis.title = "Time"

        time_plot.tools.append(PanTool(time_plot))

        zoomtool = ZoomTool(time_plot, drag_button='right', always_on=True)
        time_plot.overlays.append(zoomtool)

        lines1 = CoordinateLineOverlay(component=time_plot,
                                       index_data=self.x1,
                                       value_data=self.y1,
                                       color=(0.75, 0.25, 0.25, 0.75),
                                       line_style='dash',
                                       line_width=1)
        time_plot.underlays.append(lines1)
        self.line_overlay1 = lines1

        lines2 = CoordinateLineOverlay(component=time_plot,
                                       index_data=self.x2,
                                       value_data=self.y2,
                                       color=(0.2, 0.5, 1.0, 0.75),
                                       line_width=3)
        time_plot.underlays.append(lines2)
        self.line_overlay2 = lines2

        return time_plot
    def _plot_default(self):
        # Create data
        x = linspace(-5, 15.0, 100)
        y = jn(3, x)
        pd = ArrayPlotData(index=x, value=y)

        zoomable_plot = Plot(pd)
        zoomable_plot.plot(('index', 'value'),
                           name='external',
                           color='red',
                           line_width=3)

        # Attach tools to the plot
        zoom = ZoomTool(component=zoomable_plot,
                        tool_mode="box",
                        always_on=False)
        zoomable_plot.overlays.append(zoom)
        zoomable_plot.tools.append(PanTool(zoomable_plot))

        # Create a second inset plot, not resizable, not zoom-able
        inset_plot = Plot(pd)
        inset_plot.plot(('index', 'value'), color='blue')
        inset_plot.set(resizable='',
                       bounds=[250, 150],
                       position=[450, 350],
                       border_visible=True)

        # Create a container and add our plots
        container = OverlayPlotContainer()
        container.add(zoomable_plot)
        container.add(inset_plot)
        return container
Exemple #20
0
def _create_plot_component():# 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 = sin(x)*y

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create the plot
    plot = Plot(pd)
    img_plot = plot.img_plot("imagedata",
                             xbounds = xbounds[:2],
                             ybounds = ybounds[:2],
                             colormap=jet)[0]

    # Tweak some of the plot properties
    plot.title = "My First Image Plot"
    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)
    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)
    return plot
Exemple #21
0
    def draw_image_plot(self):
        '''
        Function called to draw the image plot.
        '''
        self.top_left = self.selection_handler.selected_indices[0][0:2]
        self.bot_right = self.selection_handler.selected_indices[0][2:4]
        data = self.table[self.top_left[0]:self.bot_right[0],
                          self.top_left[1]:self.bot_right[1]]
        plotdata = ArrayPlotData(imagedata=data)
        plot = Plot(plotdata)
        plot.img_plot('imagedata')
        plot.tools.append(PanTool(plot))
        plot.tools.append(ZoomTool(plot))
        plot.tools.append(TraitsTool(plot))
        self.container.add(plot)

        #colorbar = ColorBar(
        #    index_mapper=LinearMapper(range=plot.color_mapper.range),
        #    color_mapper = plot.color_mapper,
        #    orientation='v'
        #)
        #self.colorbar = ColorBar
        #self.container.add(colorbar)

        self.container.request_redraw()
    def _plot_default(self):
        # Create starting points for the vectors.
        numpts = self.numpts
        x = sort(random(numpts))
        y = random(numpts)

        # Create vectors.
        vectorlen = self.vectorlen
        vectors = array(
            (random(numpts) * vectorlen, random(numpts) * vectorlen)).T

        data = ArrayPlotData()
        data.set_data('index', x)
        data.set_data('value', y)
        data.set_data('vectors', vectors)
        quiverplot = Plot(data)
        quiverplot.quiverplot(('index', 'value', 'vectors'))

        # Attach some tools to the plot
        quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift"))
        zoom = ZoomTool(quiverplot)
        quiverplot.overlays.append(zoom)

        container = OverlayPlotContainer(quiverplot, padding=50)

        return container
Exemple #23
0
def _create_plot_component():

    # Create some x-y data series (with NaNs) to plot
    x = linspace(-5.0, 15.0, 500)
    x[75:125] = nan
    x[200:250] = nan
    x[300:330] = nan
    pd = ArrayPlotData(index = x)
    pd.set_data("value1", jn(0, x))
    pd.set_data("value2", jn(1, x))

    # Create some line and scatter plots of the data
    plot = Plot(pd)
    plot.plot(("index", "value1"), name="j_0(x)", color="red", width=2.0)
    plot.plot(("index", "value2"), type="scatter", marker_size=1,
              name="j_1(x)", color="green")

    # Tweak some of the plot properties
    plot.title = "Plots with NaNs"
    plot.padding = 50
    plot.legend.visible = True

    # 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)

    return plot
Exemple #24
0
def _create_plot_component():

    # Create a random scattering of XY pairs
    x = random.uniform(0.0, 10.0, 50)
    y = random.uniform(0.0, 5.0, 50)
    pd = ArrayPlotData(x=x, y=y)
    plot = Plot(pd, border_visible=True, overlay_border=True)

    scatter = plot.plot(("x", "y"), type="scatter", color="lightblue")[0]

    # Tweak some of the plot properties
    plot.set(title="Scatter Inspector Demo", padding=50)

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    plot.overlays.append(ZoomTool(plot))

    # Attach the inspector and its overlay
    scatter.tools.append(ScatterInspector(scatter))
    overlay = ScatterInspectorOverlay(scatter,
                                      hover_color="red",
                                      hover_marker_size=6,
                                      selection_marker_size=6,
                                      selection_color="yellow",
                                      selection_outline_color="purple",
                                      selection_line_width=3)
    scatter.overlays.append(overlay)

    return plot
Exemple #25
0
    def __init__(self, expl_var=None, **kwargs):
        """Constructor signature.

        :param expl_var: Calibrated and validated explained variance for each calculated PC.
        :type pc_matrix: DataSet

        Returns:
          A new created plot object

        """
        data = EVPlotData()
        super(EVLinePlot, self).__init__(data, **kwargs)

        if expl_var is not None:
            # FIXME: Do more inteligente coloring based on the data set.style
            self.add_EV_set(expl_var.mat.xs('calibrated'), 'darkviolet', 'Calibrated', expl_var)
            self.add_EV_set(expl_var.mat.xs('validated'), 'darkgoldenrod', 'Validated', expl_var)

        self.x_axis.title = "# of principal components"
        self.y_axis.title = "Explained variance [%]"
        self.x_axis.tick_interval = 1.0
        self.legend_alignment = 'ul'
        self.legend.visible = True

        self.tools.append(PanTool(self))
        self.overlays.append(ZoomTool(self, tool_mode="box",always_on=False))
def _create_plot_component():

    # Create some data
    numpts = 1000
    x = numpy.arange(0, numpts)
    y = numpy.random.random(numpts)
    marker_size = numpy.random.normal(4.0, 4.0, numpts)

    # Create a plot data object and give it this data
    pd = ArrayPlotData()
    pd.set_data("index", x)
    pd.set_data("value", y)

    # Create the plot
    plot = Plot(pd)
    plot.plot(("index", "value"),
              type="scatter",
              marker="circle",
              index_sort="ascending",
              color=(1.0, 0.0, 0.74, 0.4),
              marker_size=marker_size,
              bgcolor="white")

    # Tweak some of the plot properties
    plot.title = "Scatter Plot"
    plot.line_width = 0.5
    plot.padding = 50

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)

    return plot
Exemple #27
0
    def __init__(self, x, y, color="blue", bgcolor="white"):
        self.y_values = y[:]
        if type(x) == ArrayDataSource:
            self.x_values = x.get_data()[:]
            plot = create_line_plot((x, self.y_values),
                                    color=color,
                                    bgcolor=bgcolor,
                                    add_grid=True,
                                    add_axis=True)
        else:
            self.x_values = x[:]
            plot = create_line_plot((self.x_values, self.y_values),
                                    color=color,
                                    bgcolor=bgcolor,
                                    add_grid=True,
                                    add_axis=True)

        plot.resizable = ""
        plot.bounds = [PLOT_SIZE, PLOT_SIZE]
        plot.unified_draw = True

        plot.tools.append(PanTool(plot, drag_button="right"))
        plot.tools.append(MoveTool(plot))
        plot.overlays.append(ZoomTool(plot, tool_mode="box", always_on=False))

        self.plot = plot
        self.numpoints = len(self.x_values)
        self.current_index = self.numpoints / 2
        self.increment = 2
Exemple #28
0
def _create_plot_component():

    # Create some RGBA image data
    image = zeros((200, 400, 4), dtype=uint8)
    image[:, 0:40, 0] += 255  # Vertical red stripe
    image[0:25, :, 1] += 255  # Horizontal green stripe; also yellow square
    image[-80:, -160:, 2] += 255  # Blue square
    image[:, :, 3] = 255

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", image)

    # Create the plot
    plot = Plot(pd, default_origin="top left")
    plot.x_axis.orientation = "top"
    img_plot = plot.img_plot("imagedata")[0]

    # Tweak some of the plot properties
    plot.bgcolor = "white"

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    plot.overlays.append(
        ZoomTool(component=plot, tool_mode="box", always_on=False))

    imgtool = ImageInspectorTool(img_plot)
    img_plot.tools.append(imgtool)
    plot.overlays.append(
        ImageInspectorOverlay(component=img_plot, image_inspector=imgtool))
    return plot
Exemple #29
0
    def _add_tool(self, toolspec):
        # depending on the kind of tool, we have to attach it to different
        # things in the plot component hierarchy.
        if toolspec.type == "regression":
            # Find the first scatterplot
            for g in self.geoms:
                if isinstance(g._renderer, chaco.ScatterPlot):
                    plot = g._renderer
                    tool = RegressionLasso(plot,
                            selection_datasource=plot.index)
                    plot.tools.append(tool)
                    plot.overlays.append(RegressionOverlay(plot, 
                                        lasso_selection=tool))
                    break
            else:
                print "Unable to find a suitable scatterplot for regression tool"

        elif toolspec.type == "pan":
            cont = self.window.get_container()
            tool = PanTool(cont)
            if toolspec.button is not None:
                tool.drag_button = toolspec.button
            cont.tools.append(tool)

        elif toolspec.type == "zoom":
            cont = self.window.get_container()
            zoom = ZoomTool(cont, tool_mode="box", always_on=False)
            cont.overlays.append(zoom)
Exemple #30
0
def _create_plot_component():
    # Create a scalar field to colormap
    xs = linspace(0, 10, 600)
    ys = linspace(0, 5, 600)
    x, y = meshgrid(xs,ys)
    z = exp(-(x**2+y**2)/100)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create the plot
    plot = Plot(pd)
    img_plot = plot.img_plot("imagedata",
                             xbounds=(0, 10),
                             ybounds=(0, 5),
                             colormap=jet)[0]

    # Tweak some of the plot properties
    plot.title = "My First Image Plot"
    plot.padding = 50

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False)
    img_plot.overlays.append(zoom)
    return plot
Exemple #31
0
 def _reset_zoomtool(self, plot):
     # Replace the old ZoomTool as retaining the same one can lead
     # to issues where the zoom out/in limit is not reset on
     # resizing the plot.
     for idx, overlay in enumerate(plot.overlays):
         if isinstance(overlay, ZoomTool):
             plot.overlays[idx] = ZoomTool(plot)
Exemple #32
0
    def _plot_default(self):
        x = linspace(-5, 10, 500)
        y = sin(x)
        y2 = 0.5 * cos(2 * x)

        view = DataView(border_visible=True)
        scatter = ScatterPlot(
            index=ArrayDataSource(x),
            value=ArrayDataSource(y),
            marker="square",
            color="red",
            outline_color="transparent",
            index_mapper=LinearMapper(range=view.index_range),
            value_mapper=LinearMapper(range=view.value_range))

        line = LinePlot(index=scatter.index,
                        value=ArrayDataSource(y2),
                        color="blue",
                        index_mapper=LinearMapper(range=view.index_range),
                        value_mapper=LinearMapper(range=view.value_range))

        # Add the plot's index and value datasources to the dataview's
        # ranges so that it can auto-scale and fit appropriately
        view.index_range.sources.append(scatter.index)
        view.value_range.sources.append(scatter.value)
        view.value_range.sources.append(line.value)

        # Add the renderers to the dataview.  The z-order is determined
        # by the order in which renderers are added.
        view.add(scatter)
        view.add(line)
        view.tools.append(PanTool(view))
        view.overlays.append(ZoomTool(view))

        return view
Exemple #33
0
    def __init__(self, plot=None, box=True, x=False, y=False, next=True,
                 prev=True, reset=False, wheel=False, to_mouse=False):

        super(ZoomBar, self).__init__(box=box, x=x, y=y,
                                      next=next, prev=prev,
                                      reset=reset, wheel=wheel)

        if isinstance(plot, DataView):
            self.zoom = ZoomTool(plot, always_on=False)
            plot.overlays.append(self.zoom)
            setattr(self.zoom, 'zoom_to_mouse', to_mouse)
            setattr(self.zoom, 'enable_wheel', False)
            setattr(self.zoom, 'zoom_factor', 1.1)

        if isinstance(plot, ColorBar):
            self.zoom = ZoomTool(plot, axis="index", tool_mode="range",
                                 always_on=True, drag_button="right")
            plot.overlays.append(self.zoom)
Exemple #34
0
class ZoomBar(HasTraits):
    
    #Attribute of the class
    zoom = ZoomTool
    zoomBox = Button(label='Box',
                     style = 'toolbar',size = -1)
    zoomX = Button(label='X',
                    style = 'toolbar', width_padding = 0,
                    orientation = 'horizontal')
    zoomY = Button(label='Y',    
                    style = 'toolbar', width_padding = 0,
                    orientation = 'vertical')
    nextZoom = Button(label='Next',
                     image = ImageResource('Button-Next-icon.png',
                                            search_path = path),
                     style = 'toolbar',
                     orientation = 'vertical')
    prevZoom = Button(label='Prev',
                     image = ImageResource('Button-Previous-icon.png',
                                            search_path = path),
                     style = 'toolbar',
                     orientation = 'vertical')
    resetZoom = Button(label='Reset',
                        image = ImageResource('Reset-icon.png',
                                            search_path = path),
                        style = 'toolbar',
                        orientation = 'vertical',
                        )
    wheelZoom = Button(label='Wheel', style = 'radio')
    
    traits_view = View(
                Group(
                    Item('zoomBox', resizable = False,
                        defined_when = 'box'),
                    Item('zoomX', resizable = False, 
                        defined_when = 'x'),
                    Item('zoomY', resizable = False,
                        defined_when = 'y'),
                    Item('prevZoom', resizable = False,
                        defined_when = 'prev'),
                    Item('nextZoom', resizable = False,
                        defined_when = 'next'),
                    Item('resetZoom', resizable = False,
                        defined_when = 'reset'),
                    Item('wheelZoom', resizable = False,
                        defined_when = 'wheel'),
                    show_labels = False,
                    orientation = 'horizontal',
                    padding = 0, 
                    show_border = True,
                    label = 'Zoom',
                    ),
                style = 'custom',
                resizable = True 
                )
    
    # Initialisation : the plot should get an instance of DataView,
    # the other keywords are switches to indicates which button should
    #be displayed
    def __init__(self,plot=None,\
                    box = True, x = False, y = False,\
                    next = True, prev = True,\
                    reset = False, wheel = False,\
                    to_mouse = False):
            
        super(ZoomBar, self).__init__(box=box,x=x,y=y,\
                                        next=next,prev=prev,\
                                        reset=reset,wheel=wheel)
                                        
        if isinstance(plot,DataView):
            self.zoom = ZoomTool(plot, always_on=False)
            plot.overlays.append(self.zoom)
            setattr(self.zoom,'zoom_to_mouse',to_mouse)
            setattr(self.zoom,'enable_wheel',False)
            setattr(self.zoom,'zoom_factor',1.1)
            
        if isinstance(plot,ColorBar):
            self.zoom = ZoomTool(plot, axis="index", tool_mode="range",
                            always_on=True, drag_button="right")
            plot.overlays.append(self.zoom)
    
    # Handler for zoomBox button : enable zoom in box mode
    def _zoomBox_fired(self):
        self.zoom.tool_mode = 'box'
        self.zoom.event_state = 'pre_selecting'
        self.zoom._enabled = True 
    
    # Handler for zoomX button : enable zoom in range mode on x axis
    def _zoomX_fired(self):
        self.zoom.tool_mode= 'range'
        self.zoom.axis = 'index'
        self.zoom.event_state = 'pre_selecting'
        self.zoom._enabled = True
    
    # Handler for zoomY button : enable zoom in range mode on y axis
    def _zoomY_fired(self):
        self.zoom.tool_mode= 'range'
        self.zoom.axis = 'value'
        self.zoom.event_state = 'pre_selecting'
        self.zoom._enabled = True
        
    # Handler for nextZoom button : go to next zoom in history  
    def _nextZoom_fired(self):
        aux = getattr(self.zoom,'_history_index')
        if aux < len(getattr(self.zoom,'_history'))-1:
            setattr(self.zoom,'_history_index',aux+1)
            self.zoom._current_state().apply(self.zoom)
    
    # Handler for nextZoom button : go to previous zoom in history
    def _prevZoom_fired(self):
        aux = getattr(self.zoom,'_history_index')
        if aux > 0:
            getattr(self.zoom,'_history')[aux].revert(self.zoom)
            setattr(self.zoom,'_history_index',aux-1)
        
    # Handler for noZoom button : go back to first view in history
    def _resetZoom_fired(self):
        aux = getattr(self.zoom,'_history_index')
        for state in self.zoom._history[::-1]:
            state.revert(self.zoom)
            if aux > 0:
                aux = setattr(self.zoom,'_history_index',aux-1)
        self.zoom._history = [self.zoom._history[0]]
    
    # Handler for wheelZoom button : enable/disable zoom with 
    #   the mouse wheel
    def _wheelZoom_fired(self):
        if getattr(self.zoom,'enable_wheel'):
            setattr(self.zoom,'enable_wheel',False)
        else:
            setattr(self.zoom,'enable_wheel',True)