How to use chaco - 10 common examples

To help you get started, we’ve selected a few chaco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / chaco / examples / demo / basic / hittest_tool.py View on Github external
def _create_plot_component():
    # make 10 random points
    x = arange(10)
    x = ArrayDataSource(x, sort_order="ascending")
    y = random_sample(10)

    # Plot the data
    pd = ArrayPlotData(x=x, y=y)

    plot = Plot(pd)
    plot.orientation = 'v'
    line_plot = plot.plot(("x", "y"))[0]

    # Add the tool to the plot both as a tool and as an overlay
    tool = HittestTool(component=plot, line_plot=line_plot)
    plot.tools.append(tool)
    plot.overlays.append(tool)

    return plot
github jonathanrocher / climate_model / Code / gsod_plot_5.py View on Github external
data_file = File()

    # Tool controls
    tool_list = List([MA, CORRELATION])
    tool_chooser = Enum(values="tool_list")
    ts_list = List()
    ts1_chooser = Enum(values="ts_list")
    ts2_chooser = Enum(values="ts_list")
    # Moving average window size (in number of observations)
    ma_window_size = Int(0) 
    # Analysis details
    ts_analysis_details = Str("No details available")
    
    # Data
    ts_data = Dict()
    arr_plot_data = Instance(ArrayPlotData, ())
    times_ds = Any()   # arraydatasource for the time axis data
    index_is_dates = Bool()

    # Plots
    ts_plot = Instance(ToolbarPlot, ())
    ts_analysis_plot = Instance(ToolbarPlot, ())

    def trait_view(self, view):
        """ Build the view. The local namespace is 
        """
        return View(
            VGroup(Item('data_file', style='simple', label="HDF file to load"), 
                   HSplit(Item('ts_plot', editor=ComponentEditor(size=(400, 600)), 
                               show_label=False),
                          VGroup(Item('tool_chooser', show_label = True, label="Choose tool"),
                                 Item('ts1_chooser', label="TS 1"),
github jonathanrocher / climate_model / Code / gsod_plot_5.py View on Github external
def update_main_plot(self):
        """ Build main plot
        """
        self.ts_plot = ToolbarPlot(self.arr_plot_data)
        for i, k in enumerate([k for k in self.ts_data.keys() if k != "index"]):
            renderer = self.ts_plot.plot(("index", k), name = k, color = colors[i % len(colors)])[0]
        if self.index_is_dates:
            # Index was an array of datetime: overwrite the x axis
            self.ts_plot.x_axis = None
            x_axis = PlotAxis(self.ts_plot, orientation="bottom",
                              tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
            self.ts_plot.overlays.append(x_axis)
            self.ts_plot.x_grid.tick_generator = x_axis.tick_generator
            
        if self.data_file:
            self.ts_plot.title = ("Time series visualization from %s" 
                                  % (os.path.split(self.data_file)[1]))
        else:
            self.ts_plot.title = "Time series visualization"
        attach_tools(self.ts_plot)

        # Attach the range selection to the last renderer; any one will do
        self.ts_plot.tools.append(RangeSelection(renderer, left_button_selects = False,
            auto_handle_event = False))
        # Attach the corresponding overlay
        self._range_selection_overlay = RangeSelectionOverlay(renderer,
github NMGRL / pychron / pychron / processing / tasks / analysis_edit / plot_editor_pane.py View on Github external
self.editor_event = self.editor
        else:
            self.event_state = 'normal'
            self.editor_event = None

        self.component.invalidate_and_redraw()


#     def normal_left_dclick(self, event):

#     def select_left_dclick(self, event):
#         self.event_state = 'normal'
#         self.editor_event = None
#         self.component.invalidate_and_redraw()

class SelectorOverlay(AbstractOverlay):
    tool = Any
    color = ColorTrait('green')

    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
        if self.tool.event_state == 'select':
            with gc:
                w, h = self.component.bounds
                x, y = self.component.x, self.component.y

                gc.set_stroke_color(self.color_)
                gc.set_line_width(4)
                gc.rect(x, y, w, h)
                gc.stroke_path()


def flatten_container(container):
github jonathanrocher / climate_model / Code / gsod_plot_4.py View on Github external
def update_main_plot(self):
        """ Build main plot
        """
        self.ts_plot = ToolbarPlot(self.arr_plot_data)
        for i, k in enumerate([k for k in self.ts_data.keys() if k != "index"]):
            renderer = self.ts_plot.plot(("index", k), name = k, color = colors[i % len(colors)])[0]
        if self.index_is_dates:
            # Index was an array of datetime: overwrite the x axis
            self.ts_plot.x_axis = None
            x_axis = PlotAxis(self.ts_plot, orientation="bottom",
                              tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
            self.ts_plot.overlays.append(x_axis)
            self.ts_plot.x_grid.tick_generator = x_axis.tick_generator
            
        if self.data_file:
            self.ts_plot.title = ("Time series visualization from %s" 
                                  % (os.path.split(self.data_file)[1]))
        else:
            self.ts_plot.title = "Time series visualization"
        attach_tools(self.ts_plot)

        # Attach the range selection to the last renderer; any one will do
        self.ts_plot.tools.append(RangeSelection(renderer, left_button_selects = False,
            auto_handle_event = False))
        # Attach the corresponding overlay
        self._range_selection_overlay = RangeSelectionOverlay(renderer,
                                    metadata_name="selections")
github jonathanrocher / climate_model / Code / gsod_plot_3.py View on Github external
tool_chooser = Enum(values="tool_list")
    ts_list = List()
    ts1_chooser = Enum(values="ts_list")
    ts2_chooser = Enum(values="ts_list")
    # Moving average window size (in number of observations)
    ma_window_size = Int(0) 
    # Analysis details
    ts_analysis_details = Str("No details available")
    
    # Data
    ts_data = Dict()
    arr_plot_data = Instance(ArrayPlotData, ())
    index_is_dates = Bool()

    # Plots
    ts_plot = Instance(ToolbarPlot)
    ts_analysis_plot = Instance(ToolbarPlot)

    def trait_view(self, view):
        """ Build the view. The local namespace is 
        """
        return View(
            VGroup(Item('data_file', style='simple', label="HDF file to load"), 
                   HSplit(Item('ts_plot', editor=ComponentEditor(size=(400, 600)), 
                               show_label=False),
                          VGroup(Item('tool_chooser', show_label = True, label="Choose tool"),
                                 Item('ts1_chooser', label="TS 1"),
                                 Item('ts2_chooser', label="TS 2",
                                      visible_when="tool_chooser in ['%s']" % CORRELATION),
                                 Item('ma_window_size', label="MA window size",
                                      visible_when="tool_chooser in ['%s']" % MA),
                                 Item('ts_analysis_plot', editor=ComponentEditor(size=(400, 600)),
github jonathanrocher / climate_model / Code / gsod_plot_4.py View on Github external
def update_main_plot(self):
        """ Build main plot
        """
        self.ts_plot = ToolbarPlot(self.arr_plot_data)
        for i, k in enumerate([k for k in self.ts_data.keys() if k != "index"]):
            renderer = self.ts_plot.plot(("index", k), name = k, color = colors[i % len(colors)])[0]
        if self.index_is_dates:
            # Index was an array of datetime: overwrite the x axis
            self.ts_plot.x_axis = None
            x_axis = PlotAxis(self.ts_plot, orientation="bottom",
                              tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
            self.ts_plot.overlays.append(x_axis)
            self.ts_plot.x_grid.tick_generator = x_axis.tick_generator
            
        if self.data_file:
            self.ts_plot.title = ("Time series visualization from %s" 
                                  % (os.path.split(self.data_file)[1]))
        else:
            self.ts_plot.title = "Time series visualization"
        attach_tools(self.ts_plot)
github jonathanrocher / climate_model / Code / gsod_plot_3.py View on Github external
ts_list = List()
    ts1_chooser = Enum(values="ts_list")
    ts2_chooser = Enum(values="ts_list")
    # Moving average window size (in number of observations)
    ma_window_size = Int(0) 
    # Analysis details
    ts_analysis_details = Str("No details available")
    
    # Data
    ts_data = Dict()
    arr_plot_data = Instance(ArrayPlotData, ())
    index_is_dates = Bool()

    # Plots
    ts_plot = Instance(ToolbarPlot)
    ts_analysis_plot = Instance(ToolbarPlot)

    def trait_view(self, view):
        """ Build the view. The local namespace is 
        """
        return View(
            VGroup(Item('data_file', style='simple', label="HDF file to load"), 
                   HSplit(Item('ts_plot', editor=ComponentEditor(size=(400, 600)), 
                               show_label=False),
                          VGroup(Item('tool_chooser', show_label = True, label="Choose tool"),
                                 Item('ts1_chooser', label="TS 1"),
                                 Item('ts2_chooser', label="TS 2",
                                      visible_when="tool_chooser in ['%s']" % CORRELATION),
                                 Item('ma_window_size', label="MA window size",
                                      visible_when="tool_chooser in ['%s']" % MA),
                                 Item('ts_analysis_plot', editor=ComponentEditor(size=(400, 600)), 
                                      show_label=False),
github hyperspy / hyperspy / hyperspy / drawing / ucc.py View on Github external
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
github LTS5 / connectomeviewer / cviewer / visualization / matrix / matrix_viewer_old.py View on Github external
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