Пример #1
0
 def plot_core(self, main, core, ref_depth_line=None):
     ''' plot core info on main plot'''
     logger.debug('replotting main cores')
     loc_index, loc, dist = self.model.core_info_dict[core.core_id]
     # first plot vertical line
     y_range = main.value_range
     ys = np.array([y_range.low, y_range.high])
     xs = ys * 0 + loc
     line = create_line_plot((xs, ys), color='lightgreen',
                             width=CORE_LINE_WIDTH)
     line.origin = 'top left'
     line.index_range = main.index_range
     main.add(line)
     # then plot boundary layers as dots on line
     if ref_depth_line is None:
         ref_depth_line = self.model.survey_line.core_depth_reference
     if ref_depth_line:
         ref_depth = ref_depth_line.depth_array[loc_index]
     else:
         ref_depth = 0
     layer_depths = core.layer_boundaries
     ys = ref_depth + layer_depths
     xs = ys * 0 + loc
     scatter = create_scatter_plot((xs, ys), color='darkgreen',
                                   marker='circle',
                                   marker_size=CORE_LINE_WIDTH + 1)
     scatter.origin = 'top left'
     scatter.value_range = main.value_range
     scatter.index_range = main.index_range
     old_scatter = main.plots.get('core_plot', [])
     if old_scatter:
         main.components.remove(old_scatter[0])
     main.add(scatter)
     main.plots['core_plot'] = [scatter]
Пример #2
0
 def _plot_default(self):
     plot_data = ArrayPlotData(index=self.sigma, value=self.mu)
     self.plot_data = plot_data
     plot = Plot(data=plot_data)
     line = create_line_plot([self.sigma, self.mu],
                             add_grid=True,
                             value_bounds=(min(self.mean), max(self.mean)),
                             add_axis=True,
                             index_sort='ascending',
                             orientation='h')
     scatter = create_scatter_plot(
         [np.sqrt(np.diag(self.covar)),
          np.squeeze(self.mean)],
         index_bounds=(line.index_range.low, line.index_range.high),
         value_bounds=(line.value_range.low, line.value_range.high),
         marker='circle',
         color='blue')
     plot.add(line)
     left, bottom = line.underlays[-2:]
     left.title = 'Return'
     bottom.title = 'Risk'
     plot.add(scatter)
     cursor = CursorTool(line, drag_button='left', color='blue')
     self.cursor = cursor
     #cursor.current_position = self.sigma[0], self.mu[0]
     line.overlays.append(cursor)
     line.tools.append(PanTool(line, drag_button='right'))
     #line.overlays.append(ZoomTool(line))
     return plot
Пример #3
0
 def plot_core(self, main, core, ref_line, loc_index, loc):
     ''' plot core info on main plot'''
     # first plot vertical line
     y_range = main.value_range
     ys = np.array([y_range.low, y_range.high])
     xs = ys * 0 + loc
     line = create_line_plot((xs, ys),
                             color='lightgreen',
                             width=CORE_LINE_WIDTH)
     line.origin = 'top left'
     line.index_range = main.index_range
     main.add(line)
     # then plot boundary layers as dots on line
     layer_depths = core.layer_boundaries
     ref_depth_line = self.model.get_ref_depth_line()
     if ref_depth_line:
         ref_depth = ref_depth_line.depth_array[loc_index]
     else:
         ref_depth = 0
     ys = ref_depth + layer_depths
     xs = ys * 0 + loc
     scatter = create_scatter_plot((xs, ys),
                                   color='darkgreen',
                                   marker='circle',
                                   marker_size=CORE_LINE_WIDTH + 1)
     scatter.origin = 'top left'
     scatter.value_range = main.value_range
     scatter.index_range = main.index_range
     main.add(scatter)
Пример #4
0
    def _setup_plots(self):
        """Creates series of Bessel function plots"""
        plots = {}
        x = arange(self.low, self.high + 0.001, (self.high - self.low) / self.numpoints)

        for i in range(self.num_funs):
            y = jn(i, x)
            if i % 2 == 1:
                plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0)
            else:
                plot = create_scatter_plot((x, y), color=tuple(COLOR_PALETTE[i]))

            if i == 0:
                value_mapper, index_mapper, legend = self._setup_plot_tools(plot)
            else:
                self._setup_mapper(plot, value_mapper, index_mapper)

            self.add(plot)
            plots["Bessel j_%d" % i] = plot

        # Set the list of plots on the legend
        legend.plots = plots

        # Add the title at the top
        self.overlays.append(PlotLabel("Bessel functions", component=self, font="swiss 16", overlay_position="top"))

        # Add the traits inspector tool to the container
        self.tools.append(TraitsTool(self))
Пример #5
0
    def make_reference_plot(self):
        ''' make reference plot for mini plot range selector'''
        x_pts = np.array(
            [self.model.distance_array.min(),
             self.model.distance_array.max()])

        y_pts = 0 * x_pts
        ref_plot = create_scatter_plot((x_pts, y_pts), color='black')
        return ref_plot
    def setUp(self):
        values = numpy.arange(10)
        self.plot = create_scatter_plot((values, values))
        self.plot.bounds = [100, 100]
        self.plot._window = self.create_mock_window()
        self.tool = ScatterInspector(component=self.plot)
        self.plot.active_tool = self.tool
        self.plot.do_layout()

        self.insp_event = None
Пример #7
0
    def make_reference_plot(self):
        ''' make reference plot for mini plot range selector'''
        x_pts = np.array([self.model.distance_array.min(),
                          self.model.distance_array.max()
                          ]
                         )

        y_pts = 0 * x_pts
        ref_plot = create_scatter_plot((x_pts, y_pts), color='black')
        return ref_plot
    def setUp(self):
        values = numpy.arange(10)
        self.plot = create_scatter_plot((values, values))
        self.plot.bounds = [100, 100]
        self.plot._window = self.create_mock_window()
        self.tool = ScatterInspector(component=self.plot)
        self.plot.active_tool = self.tool
        self.plot.do_layout()

        self.insp_event = None
Пример #9
0
 def test_scatter_fast(self):
     """ Coverage test to check basic case works """
     size = (50, 50)
     scatterplot = create_scatter_plot(
         data=[range(10), range(10)],
         border_visible=False,
     )
     scatterplot.outer_bounds = list(size)
     gc = PlotGraphicsContext(size)
     gc.render_component(scatterplot)
     actual = gc.bmp_array[:, :, :]
     self.assertFalse(alltrue(actual == 255))
 def test_scatter_circle(self):
     """ Coverage test to check circles work """
     size = (50, 50)
     scatterplot = create_scatter_plot(
         data=[list(sm.xrange(10)), list(sm.xrange(10))],
         marker="circle",
         border_visible=False,
     )
     scatterplot.outer_bounds = list(size)
     gc = PlotGraphicsContext(size)
     gc.render_component(scatterplot)
     actual = gc.bmp_array[:, :, :]
     self.assertFalse(alltrue(actual == 255))
Пример #11
0
 def test_scatter_circle(self):
     """ Coverage test to check circles work """
     size = (50, 50)
     scatterplot = create_scatter_plot(
         data=[list(range(10)), list(range(10))],
         marker="circle",
         border_visible=False,
     )
     scatterplot.outer_bounds = list(size)
     gc = PlotGraphicsContext(size)
     gc.render_component(scatterplot)
     actual = gc.bmp_array[:, :, :]
     self.assertFalse(alltrue(actual == 255))
Пример #12
0
 def test_scatter_slow(self):
     """ Coverage test to check multiple marker size works """
     size = (50, 50)
     scatterplot = create_scatter_plot(
         data=[range(10), range(10)],
         marker="circle",
         border_visible=False,
         marker_size=range(1, 11),
     )
     scatterplot.outer_bounds = list(size)
     gc = PlotGraphicsContext(size)
     gc.render_component(scatterplot)
     actual = gc.bmp_array[:, :, :]
     self.assertFalse(alltrue(actual == 255))
Пример #13
0
    def _plots_default(self):
        plotdata = self.get_data_sets()
        plots = Plot(plotdata)
        plotsDict = {}

        # plot background sonar image and impound lines
        xbounds = self.model.survey_rng_m
        ybounds = self.model.depth_m
        plots.img_plot("sonarimg", colormap=jet,
                        xbounds=xbounds, ybounds=ybounds)
        ip = plots.plot(('impound1_X','impound1_Y'), type='line', marker='square')
        plotsDict['Impoundment line'] = ip
        plots.x_axis.title = 'Distance along survey line (m)'
        plots.y_axis.title = 'Depth (m)'

        # add core samples as scatter with separate y-axis
        corex = plotdata.get_data('coreX')
        corey = plotdata.get_data('coreY')
        scatter = create_scatter_plot((corex,corey), marker='diamond',
                                       color='red' )
        scatter.index_range = plots.index_range
        axis = PlotAxis(scatter, orientation='right')
        axis.title = 'Core sample dist from survey line (m)'
        scatter.underlays.append(axis)
        plots.add(scatter)

        # create vertical line for indicating selected core sample position
        vals1 = [0 for x in corey]
        vline = create_line_plot((corey,vals1), color='blue', orientation='v')
        vline.value_range = scatter.index_range
        plots.add(vline)

        # Add Legend
        legend = Legend(component=plots, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="left"))
        legend.plots = plotsDict
        plots.overlays.append(legend)

        # Add tools
        scatter.tools.append(PickTool(scatter))
        plots.tools.append(TraceTool(plots))
        plots.tools.append(PanTool(plots))
        plots.tools.append(ZoomTool(plots))

        return plots
Пример #14
0
 def test_data_label_arrow_not_visible(self):
     # Regression test for https://github.com/enthought/chaco/issues/281
     # Before the problem was fixed, this test (specifically, using
     # arrow_visible=False in the DataLabel constructor) would raise an
     # exception because of an undefined reference.
     size = (50, 50)
     plot = create_scatter_plot(data=[range(10), range(10)])
     label = DataLabel(component=plot,
                       data_point=(4, 4),
                       marker_color="red",
                       marker_size=3,
                       label_position=(20, 50),
                       label_style='bubble',
                       label_text="Something interesting",
                       label_format="at x=%(x).2f, y=%(y).2f",
                       arrow_visible=False)
     plot.overlays.append(label)
     plot.outer_bounds = list(size)
     gc = PlotGraphicsContext(size)
     gc.render_component(plot)
Пример #15
0
def do_plotv(session, *args, **kw):
    """ Creates a list of plots from the data in ``*args`` and options in
    ``**kw``, according to the docstring on commands.plot().
    """

    sort = kw.get("sort", "none")
    sources_list = make_data_sources(session, sort, *args)

    plot_type = kw.get("type", "line")
    if plot_type == "scatter":
        plots = [create_scatter_plot(sources) for sources in sources_list]
    elif plot_type == "line":
        plots = [create_line_plot(sources) for sources in sources_list]
    else:
        raise ChacoShellError("Unknown plot type '%s'." % plot_type)

    for plot in plots:
        plot.orientation = kw.get("orientation", "h")

    return plots
Пример #16
0
 def test_data_label_arrow_not_visible(self):
     # Regression test for https://github.com/enthought/chaco/issues/281
     # Before the problem was fixed, this test (specifically, using
     # arrow_visible=False in the DataLabel constructor) would raise an
     # exception because of an undefined reference.
     size = (50, 50)
     plot = create_scatter_plot(data=[range(10), range(10)])
     label = DataLabel(component=plot,
                       data_point=(4, 4),
                       marker_color="red",
                       marker_size=3,
                       label_position=(20, 50),
                       label_style='bubble',
                       label_text="Something interesting",
                       label_format="at x=%(x).2f, y=%(y).2f",
                       arrow_visible=False)
     plot.overlays.append(label)
     plot.outer_bounds = list(size)
     gc = PlotGraphicsContext(size)
     gc.render_component(plot)
Пример #17
0
def do_plotv(session, *args, **kw):
    """ Creates a list of plots from the data in ``*args`` and options in
    ``**kw``, according to the docstring on commands.plot().
    """

    sort = kw.get("sort", "none")
    sources_list = make_data_sources(session, sort, *args)

    plot_type = kw.get("type", "line")
    if plot_type == "scatter":
        plots = [create_scatter_plot(sources) for sources in sources_list]
    elif plot_type == "line":
        plots = [create_line_plot(sources) for sources in sources_list]
    else:
        raise ChacoShellError, "Unknown plot type '%s'." % plot_type

    for plot in plots:
        plot.orientation = kw.get("orientation", "h")


    return plots
Пример #18
0
    def _make_container(self):
        container = chaco.HPlotContainer(padding=40, spacing=25)
        broadcaster=chaco_tools.BroadcasterTool()

        self.data.append((chaco.ArrayDataSource([]), chaco.ArrayDataSource([])))
        plot = chaco.create_scatter_plot((self.data[-1][0], self.data[-1][1]),
                marker='circle',
                marker_size=2.0,
                add_grid=True,
                add_axis=True,
                border_visible=True)
        plot.line_width=0.0
        zoom = chaco_tools.ZoomTool(plot)
        pan = chaco_tools.PanTool(plot)

        broadcaster.tools.append(zoom)
        broadcaster.tools.append(pan)

        plot.bgcolor = 'white'
        container.add(plot)
        container.tools.append(broadcaster)
        return container
Пример #19
0
    def test_scatter_custom(self):
        """ Coverage test to check custom markers work """
        # build path
        path = CompiledPath()
        path.move_to(-5, -5)
        path.line_to(5, 5)
        path.line_to(5, -5)
        path.line_to(-5, 5)
        path.line_to(-5, -5)

        size = (50, 50)
        scatterplot = create_scatter_plot(
            data=[range(10), range(10)],
            marker='custom',
            border_visible=False,
        )
        scatterplot.custom_symbol = path
        scatterplot.outer_bounds = list(size)
        gc = PlotGraphicsContext(size)
        gc.render_component(scatterplot)
        actual = gc.bmp_array[:, :, :]
        self.assertFalse(alltrue(actual == 255))
Пример #20
0
    def _setup_plots(self):
        """Creates series of Bessel function plots"""
        plots = {}
        x = arange(self.low, self.high + 0.001,
                   (self.high - self.low) / self.numpoints)

        for i in range(self.num_funs):
            y = jn(i, x)
            if i % 2 == 1:
                plot = create_line_plot((x, y),
                                        color=tuple(COLOR_PALETTE[i]),
                                        width=2.0)
            else:
                plot = create_scatter_plot((x, y),
                                           color=tuple(COLOR_PALETTE[i]))

            if i == 0:
                value_mapper, index_mapper, legend = \
                    self._setup_plot_tools(plot)
            else:
                self._setup_mapper(plot, value_mapper, index_mapper)

            self.add(plot)
            plots["Bessel j_%d" % i] = plot

        # Set the list of plots on the legend
        legend.plots = plots

        # Add the title at the top
        self.overlays.append(
            PlotLabel("Bessel functions",
                      component=self,
                      font="swiss 16",
                      overlay_position="top"))

        # Add the traits inspector tool to the container
        self.tools.append(TraitsTool(self))
Пример #21
0
def _create_plot_component():
    container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                     bgcolor = "lightgray", use_backbuffer=True)

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

    now = time()
    timex = linspace(now, now+7*24*3600, numpoints)

    # Plot some bessel functions
    value_mapper = None
    index_mapper = None
    plots = {}
    for i in range(10):
        y = jn(i, x)
        if i%2 == 1:
            plot = create_line_plot((timex,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
            plot.index.sort_order = "ascending"
        else:
            plot = create_scatter_plot((timex,y), color=tuple(COLOR_PALETTE[i]))
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            value_mapper = plot.value_mapper
            index_mapper = plot.index_mapper
            left, bottom = add_default_axes(plot)
            left.tick_generator = ScalesTickGenerator()
            bottom.tick_generator = ScalesTickGenerator(scale=CalendarScaleSystem())
            add_default_grids(plot, tick_gen=bottom.tick_generator)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)

        if i==0:
            plot.tools.append(PanTool(plot))
            zoom = ZoomTool(plot, tool_mode="box", always_on=False)
            plot.overlays.append(zoom)
            # 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)

        container.add(plot)
        plots["Bessel j_%d"%i] = plot

    # Set the list of plots on the legend
    legend.plots = plots

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

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Пример #22
0
def _create_plot_component():
    container = OverlayPlotContainer(
        padding=50,
        fill_padding=True,
        bgcolor="lightgray",
        use_backbuffer=True)

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

    now = time()
    timex = linspace(now, now + 7 * 24 * 3600, numpoints)

    # Plot some bessel functions
    value_mapper = None
    index_mapper = None
    plots = {}
    for i in range(10):
        y = jn(i, x)
        if i % 2 == 1:
            plot = create_line_plot(
                (timex, y), color=tuple(COLOR_PALETTE[i]), width=2.0)
            plot.index.sort_order = "ascending"
        else:
            plot = create_scatter_plot(
                (timex, y), color=tuple(COLOR_PALETTE[i]))
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            value_mapper = plot.value_mapper
            index_mapper = plot.index_mapper
            left, bottom = add_default_axes(plot)
            left.tick_generator = ScalesTickGenerator()
            bottom.tick_generator = ScalesTickGenerator(
                scale=CalendarScaleSystem())
            add_default_grids(plot, tick_gen=bottom.tick_generator)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)

        if i == 0:
            plot.tools.append(PanTool(plot))
            zoom = ZoomTool(plot, tool_mode="box", always_on=False)
            plot.overlays.append(zoom)
            # 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)

        container.add(plot)
        plots["Bessel j_%d" % i] = plot

    # Set the list of plots on the legend
    legend.plots = plots

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

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container