コード例 #1
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
コード例 #2
0
ファイル: edit_line.py プロジェクト: dpinte/chaco
def _create_plot_component():

    container = OverlayPlotContainer(padding=50,
                                     fill_padding=True,
                                     bgcolor="lightgray",
                                     use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 30
    low = -5
    high = 15.0
    x = linspace(low, high, numpoints)
    y = jn(0, x)

    lineplot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[0]),
                                width=2.0)
    lineplot.selected_color = "none"
    scatter = ScatterPlot(index=lineplot.index,
                          value=lineplot.value,
                          index_mapper=lineplot.index_mapper,
                          value_mapper=lineplot.value_mapper,
                          color=tuple(COLOR_PALETTE[0]),
                          marker_size=5)
    scatter.index.sort_order = "ascending"

    scatter.bgcolor = "white"
    scatter.border_visible = True

    add_default_grids(scatter)
    add_default_axes(scatter)

    scatter.tools.append(PanTool(scatter, drag_button="right"))

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

    scatter.tools.append(PointDraggingTool(scatter))

    container.add(lineplot)
    container.add(scatter)

    # Add the title at the top
    container.overlays.append(
        PlotLabel("Line Editor",
                  component=container,
                  font="swiss 16",
                  overlay_position="top"))

    return container
コード例 #3
0
ファイル: plot_conjoint.py プロジェクト: TGXnet/consumercheck
    def _add_lines(self):
        # index = self.mk_ads('index')
        index = ArrayDataSource(range(len(self.index_labels)))
        value = self.mk_ads('values')

        # Create lineplot
        plot_line = LinePlot(
            index=index, index_mapper=self.index_mapper,
            value=value, value_mapper=self.value_mapper,
            name='line')

        # Add datapoint enhancement
        plot_scatter = ScatterPlot(
            index=index, index_mapper=self.index_mapper,
            value=value, value_mapper=self.value_mapper,
            color="blue", marker_size=5,
            name='scatter',
        )

        self.add(plot_line, plot_scatter)
コード例 #4
0
    def _plot_default(self):
        container = DataView()

        xds = FunctionDataSource(func=self.xfunc)
        yds = FunctionDataSource(func=self.yfunc)

        xmapper = container.x_mapper
        ymapper = container.y_mapper

        xds.data_range = xmapper.range
        yds.data_range = xmapper.range

        xmapper.range.set_bounds(-5, 10)
        ymapper.range.set_bounds(-1, 1.2)

        plot = ScatterPlot(index=xds,
                           value=yds,
                           index_mapper=xmapper,
                           value_mapper=ymapper,
                           color="green",
                           marker="circle",
                           marker_size=3,
                           line_width=0)

        plot2 = LinePlot(index=xds,
                         value=yds,
                         index_mapper=xmapper,
                         value_mapper=ymapper,
                         color="lightgray")

        container.add(plot2, plot)
        plot.tools.append(
            PanTool(plot, constrain_direction="x", constrain=True))
        plot.tools.append(ZoomTool(plot, axis="index", tool_mode="range"))

        return container
コード例 #5
0
def create_gridded_scatter_plot(x,
                                y,
                                orientation="h",
                                color="red",
                                width=1.0,
                                fill_color="red",
                                marker="square",
                                marker_size=2,
                                value_mapper_class=LinearMapper,
                                padding=30):

    assert len(x) == len(y)

    # If you know it is monotonically increasing, sort_order can
    # be set to 'ascending'
    index = ArrayDataSource(x, sort_order='none')
    value = ArrayDataSource(y, sort_order="none")

    index_range = DataRange1D(tight_bounds=False)
    index_range.add(index)
    index_mapper = LinearMapper(range=index_range)

    value_range = DataRange1D(tight_bounds=False)
    value_range.add(value)
    value_mapper = value_mapper_class(range=value_range)

    plot = ScatterPlot(
        index=index,
        value=value,
        index_mapper=index_mapper,
        value_mapper=value_mapper,
        orientation=orientation,
        color=color,
        fill_color=fill_color,
        marker=marker,
        marker_size=marker_size,
        padding=[40, 15, 15, 20],  # left, right, top, bottom
        border_visible=True,
        border_width=1,
        bgcolor="white",
        use_backbuffer=True,
        backbuffer_padding=False,
        unified_draw=True,
        draw_layer="plot",
        overlay_border=True)

    vertical_grid = PlotGrid(component=plot,
                             mapper=index_mapper,
                             orientation='vertical',
                             line_color="gray",
                             line_style='dot',
                             use_draw_order=True)

    horizontal_grid = PlotGrid(component=plot,
                               mapper=value_mapper,
                               orientation='horizontal',
                               line_color="gray",
                               line_style='dot',
                               use_draw_order=True)

    vertical_axis = PlotAxis(orientation='left',
                             mapper=plot.value_mapper,
                             use_draw_order=True)

    horizontal_axis = PlotAxis(orientation='bottom',
                               title='Time (s)',
                               mapper=plot.index_mapper,
                               use_draw_order=True)

    plot.underlays.append(vertical_grid)
    plot.underlays.append(horizontal_grid)

    # Have to add axes to overlays because we are backbuffering the main plot,
    # and only overlays get to render in addition to the backbuffer.
    plot.overlays.append(vertical_axis)
    plot.overlays.append(horizontal_axis)
    return plot
コード例 #6
0
 def _plot_default(self):
     plotdata = ArrayPlotData()
     plot = MapPlot(plotdata,
                    auto_grid=False,
                    bgcolor=self.land_color)
     plot.x_axis.visible = False
     plot.y_axis.visible = False
     plot.padding = (0, 0, 0, 0)
     plot.border_visible = False
     index_mapper = LinearMapper(range=plot.index_range)
     value_mapper = LinearMapper(range=plot.value_range)
     if self.model.lake is not None:
         line_lengths = [l.length for l in self.model.lake.shoreline]
         idx_max = line_lengths.index(max(line_lengths))
         for num, l in enumerate(self.model.lake.shoreline):
             line = np.array(l.coords)
             x = line[:,0]
             y = line[:,1]
             # assume that the longest polygon is lake, all others islands
             if num == idx_max:
                 color = self.lake_color
             else:
                 color = self.land_color
             polyplot = PolygonPlot(index=ArrayDataSource(x),
                                    value=ArrayDataSource(y),
                                    edge_color=self.shore_color,
                                    face_color=color,
                                    index_mapper=index_mapper,
                                    value_mapper=value_mapper)
             plot.add(polyplot)
     for num, line in enumerate(self.survey_lines):
         coords = np.array(line.navigation_line.coords)
         x = coords[:,0]
         y = coords[:,1]
         x_key = 'x-line' + str(num)
         y_key = 'y-line' + str(num)
         plotdata.set_data(x_key, x)
         plotdata.set_data(y_key, y)
         self.line_plots[line.name] = plot.plot((x_key, y_key),
                                                color=self.line_color)
     for core in self.model.core_samples:
         x, y = core.location
         scatterplot = ScatterPlot(index=ArrayDataSource([x]),
                                    value=ArrayDataSource([y]),
                                    marker='circle',
                                    color=self.core_color,
                                    outline_color=self.core_color,
                                    index_mapper=index_mapper,
                                    value_mapper=value_mapper)
         plot.add(scatterplot)
     self._set_line_colors()
     if self.model.lake is not None:
         x_min, y_min, x_max, y_max = self.model.lake.shoreline.bounds
         index_mapper.range.high = x_max
         index_mapper.range.low = x_min
         value_mapper.range.high = y_max
         value_mapper.range.low = y_min
     plot.tools.append(PanTool(plot))
     plot.tools.append(ZoomTool(plot))
     self.line_select_tool = LineSelectTool(plot, line_plots=self.line_plots)
     # single click in map sets 'select point':  toggle in selected lines
     self.line_select_tool.on_trait_event(self.select_point, 'select_point')
     # double click in map sets 'current point': change current survey line
     self.line_select_tool.on_trait_event(self.current_point, 'current_point')
     plot.tools.append(self.line_select_tool)
     return plot