Пример #1
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=viridis)[0]

    # Tweak some of the plot properties
    plot.title = "Image Plot with Lasso"
    plot.padding = 50

    lasso_selection = LassoSelection(component=img_plot)
    lasso_selection.on_trait_change(lasso_updated, "disjoint_selections")
    lasso_overlay = LassoOverlay(lasso_selection=lasso_selection,
                                 component=img_plot)
    img_plot.tools.append(lasso_selection)
    img_plot.overlays.append(lasso_overlay)
    return plot
Пример #2
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 = "Image Plot with Lasso"
    plot.padding = 50

    lasso_selection = LassoSelection(component=img_plot)
    lasso_selection.on_trait_change(lasso_updated, "disjoint_selections")
    lasso_overlay = LassoOverlay(lasso_selection=lasso_selection, component=img_plot)
    img_plot.tools.append(lasso_selection)
    img_plot.overlays.append(lasso_overlay)
    return plot
Пример #3
0
    def overlay_selection(self, plot):
        lasso_selection = LassoSelection(component=plot,
                                         selection_datasource=plot.index,
                                         drag_button="left")
        plot.active_tool = lasso_selection
        plot.tools.append(ScatterInspector(plot))
        lasso_overlay = LassoOverlay(lasso_selection=lasso_selection,
                                     component=plot)
        plot.overlays.append(lasso_overlay)

        # Uncomment this if you would like to see incremental updates:
        # lasso_selection.incremental_select = True
        self.index_datasource = plot.index
 def install(self):
     scatter = self.widget.scatter
     self._tool = tool = LassoSelection(scatter,
         drag_button = 'left',
         selection_datasource = scatter.index,
         metadata_name = 'lasso_selection',
     )
     tool.on_trait_change(self._selection_changed, 'selection_changed')
     
     self._overlay = LassoOverlay(scatter,
         lasso_selection = self._tool,
     )
     scatter.tools.append(self._tool)
     scatter.overlays.append(self._overlay)
Пример #5
0
def _create_plot_component():

    # Create some data
    npts = 2000
    x = sort(random(npts))
    y = random(npts)

    # Create a plot data obect 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",
              name="my_plot",
              marker="circle",
              index_sort="ascending",
              color="red",
              marker_size=4,
              bgcolor="white")

    # Tweak some of the plot properties
    plot.title = "Scatter Plot With Lasso Selection"
    plot.line_width = 1
    plot.padding = 50

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

    # Attach some tools to the plot
    lasso_selection = LassoSelection(component=my_plot,
                                     selection_datasource=my_plot.index,
                                     drag_button="left")
    #drag_button="right")
    my_plot.active_tool = lasso_selection
    my_plot.tools.append(ScatterInspector(my_plot))
    lasso_overlay = LassoOverlay(lasso_selection=lasso_selection,
                                 component=my_plot)
    my_plot.overlays.append(lasso_overlay)

    # Uncomment this if you would like to see incremental updates:
    #lasso_selection.incremental_select = True

    return plot
Пример #6
0
    def _plot_default(self):
        stations = self.stations
        lon, lat = self._proj(stations['LON'].view(numpy.ndarray),
                              stations['LAT'].view(numpy.ndarray))

        shift = self._shift
        lon = (lon + shift / 2.) / (shift)
        lat = (lat + shift / 2.) / (shift)

        plot = Plot(ArrayPlotData(index=lon, value=lat))
        plot.plot(
            ("index", "value"),
            type="scatter",
            name="stations",
            marker="dot",
            outline_color='black',
            color=(1., 0., 0., 0.2),
            line_width=1.,
            marker_size=1,
        )

        mbtiles_fname = os.path.join('Data', 'tiles.mbtiles')
        if os.path.exists(mbtiles_fname):
            tile_cache = MBTileManager(filename=mbtiles_fname,
                                       min_level=0,
                                       max_level=7)
        else:
            tile_cache = HTTPTileManager(
                min_level=0,
                max_level=6,
                server='oatile1.mqcdn.com',
                url='/tiles/1.0.0/sat/%(zoom)d/%(row)d/%(col)d.jpg',
            )

        # Right now, some of the tools are a little invasive, and we need the
        # actual ScatterPlot object to give to them
        scatter = plot.plots['stations'][0]

        map = Map(scatter, tile_cache=tile_cache, alpha=0.8, zoom_level=2)
        scatter.underlays.append(map)

        map.on_trait_change(lambda new: self._update_scatter(scatter, new),
                            'zoom_level')
        self._update_scatter(scatter, map.zoom_level)

        lasso_selection = LassoSelection(component=scatter,
                                         selection_datasource=scatter.index)

        scatter.tools.append(lasso_selection)
        scatter.overlays.append(
            LassoOverlay(component=scatter,
                         selection_fill_color='lawngreen',
                         selection_border_color='lightgreen',
                         selection_alpha=0.5,
                         selection_border_width=2.0,
                         lasso_selection=lasso_selection))

        scatter.overlays.append(
            ScatterInspectorOverlay(scatter,
                                    selection_metadata_name='selection',
                                    selection_marker_size=4,
                                    selection_color="lawngreen"))
        scatter.index.on_trait_change(self._metadata_handler,
                                      "metadata_changed")

        scatter.tools.append(PanTool(scatter, drag_button='right'))
        scatter.tools.append(ZoomTool(scatter))

        plot.index_axis.title = "Longitude"
        plot.index_axis.tick_label_formatter = self._convert_lon
        plot.value_axis.title = "Latitude"
        plot.value_axis.tick_label_formatter = self._convert_lat

        plot.padding_right = plot.padding_top = 2

        container = OverlayPlotContainer(use_backbuffer=True,
                                         bgcolor="sys_window")
        container.add(plot)
        container.bgcolor = "sys_window"

        return container