コード例 #1
0
ファイル: chaco_util.py プロジェクト: NeuroArchive/morphforge
def _create_plot_component(title, initial_values=None, on_change_functor=None):

    #return OverlayPlotContainer()


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

    if initial_values:
        x = initial_values[0]
        y = initial_values[1]
    else:
        # 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 = 2)
    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)

    point_dragging_tool = PointDraggingTool(scatter)
    point_dragging_tool.on_change_functor = on_change_functor
    scatter.tools.append(point_dragging_tool)


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

    #container.mx = lineplot.index.get_data()
    #container.my = lineplot.value.get_data()
    container.lineplot = lineplot
    return container
コード例 #2
0
ファイル: edit_line.py プロジェクト: enthought/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)
    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
ファイル: mapplot.py プロジェクト: IEEERobotics/high-level
  def _plot_default(self):

    data_xy = self.map.xy()

    x_ds = ArrayDataSource(data_xy[:,0] * self.map.scale)
    y_ds = ArrayDataSource(data_xy[:,1] * self.map.scale)
    self.x_ds = x_ds
    self.y_ds = y_ds

    x_dr = DataRange1D(x_ds)
    y_dr = DataRange1D(y_ds)
    x_dr.set_bounds(0, self.map.x_inches)  # auto ranging won't work if a side has no walls
    y_dr.set_bounds(0, self.map.y_inches)

    markersize = max( min(475/self.map.ydim, 500/self.map.xdim), 1 )

    # marker_size needs to be roughly plot.bounds[0] / (xdim*2)
    plot = ScatterPlot(index = x_ds, value = y_ds,
                       index_mapper = LinearMapper(range = x_dr),
                       value_mapper = LinearMapper(range = y_dr),
                       color = "black", bgcolor = "white", 
                       marker = "square", marker_size = markersize)

    plot.aspect_ratio = float(self.xdim) / float(self.ydim)

    pgx = PlotGrid(component = plot, mapper = plot.index_mapper, orientation = 'vertical',
                   grid_interval = 1, line_width = 1.0, line_style = "dot", line_color = "lightgray")
    pgy = PlotGrid(component = plot, mapper = plot.value_mapper, orientation = 'horizontal',
                   grid_interval = 1, line_width = 1.0, line_style = "dot", line_color = "lightgray")
    plot.underlays.append(pgx)
    plot.underlays.append(pgy)
    add_default_axes(plot)

    # this is meaningless until we're actually rendered
    #print plot.bounds

    return plot    
コード例 #4
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)
コード例 #5
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
コード例 #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