コード例 #1
0
def create_multi_line_plot_renderer(x_index, y_index, data, amplitude=0.5):
    # Create the data source for the MultiLinePlot.
    ds = MultiArrayDataSource(data=data)

    xs = ArrayDataSource(x_index, sort_order='ascending')
    xrange = DataRange1D()
    xrange.add(xs)

    ys = ArrayDataSource(y_index, sort_order='ascending')
    yrange = DataRange1D()
    yrange.add(ys)

    mlp = MultiLinePlot(
        index=xs,
        yindex=ys,
        index_mapper=LinearMapper(range=xrange),
        value_mapper=LinearMapper(range=yrange),
        value=ds,
        global_max=np.nanmax(data),
        global_min=np.nanmin(data),
        #use_global_bounds=True,
        #default_origin='top left', origin='top left',
        #**kw
    )
    mlp.normalized_amplitude = amplitude
    return mlp
コード例 #2
0
def get_quiver_plot():
    NPOINTS = 250

    # points are distributed uniformly between -1 and 1
    xs = np.random.uniform(low=-1.0, high=1.0, size=(NPOINTS, ))
    ys = np.random.uniform(low=-1.0, high=1.0, size=(NPOINTS, ))

    x, y = get_data_sources(x=xs, y=ys)
    x_mapper, y_mapper = get_mappers(x, y)

    # vectors are tangent to a circle centered in (0, 0) and the size depends
    # on the radius
    r = np.sqrt(xs * xs + ys * ys) * 20.0
    v = r * np.array([-np.sin(np.arctan2(ys, xs)), np.cos(np.arctan2(ys, xs))])
    v_source = MultiArrayDataSource(v.T)

    quiver_plot = QuiverPlot(index=x,
                             value=y,
                             vectors=v_source,
                             index_mapper=x_mapper,
                             value_mapper=y_mapper,
                             aspect_ratio=1.0)

    add_axes(quiver_plot, x_label='x', y_label='y')

    return quiver_plot
コード例 #3
0
    def __init__(self, x_index, y_index, data, **kw):
        super(MyPlot, self).__init__(**kw)

        # Create the data source for the MultiLinePlot.
        ds = MultiArrayDataSource(data=data)

        xs = ArrayDataSource(x_index, sort_order='ascending')
        xrange = DataRange1D()
        xrange.add(xs)

        ys = ArrayDataSource(y_index, sort_order='ascending')
        yrange = DataRange1D()
        yrange.add(ys)

        mlp = MultiLinePlot(index=xs,
                            yindex=ys,
                            index_mapper=LinearMapper(range=xrange),
                            value_mapper=LinearMapper(range=yrange),
                            value=ds,
                            global_max=np.nanmax(data),
                            global_min=np.nanmin(data),
                            **kw)

        self.plot = Plot()
        self.plot.add(mlp)
コード例 #4
0
    def _multi_line_plot_renderer_default(self):
        """Create the default MultiLinePlot instance."""

        xs = ArrayDataSource(self.model.x_index, sort_order='ascending')
        xrange = DataRange1D()
        xrange.add(xs)

        ys = ArrayDataSource(self.model.y_index, sort_order='ascending')
        yrange = DataRange1D()
        yrange.add(ys)

        # The data source for the MultiLinePlot.
        ds = MultiArrayDataSource(data=self.model.data)

        multi_line_plot_renderer = \
            MultiLinePlot(
                index = xs,
                yindex = ys,
                index_mapper = LinearMapper(range=xrange),
                value_mapper = LinearMapper(range=yrange),
                value=ds,
                global_max = self.model.data.max(),
                global_min = self.model.data.min())

        return multi_line_plot_renderer
コード例 #5
0
ファイル: ChacoQWidget.py プロジェクト: spherik/meg
    def _signals_data_model_changed(self, old, new):
        print('model_changed')

        xs = ArrayDataSource(self.signals_data_model.x_index,
                             sort_order='ascending')
        xrange = DataRange1D()
        xrange.add(xs)

        ys = ArrayDataSource(self.signals_data_model.y_index,
                             sort_order='ascending')
        yrange = DataRange1D()
        yrange.add(ys)

        # The data source for the MultiLinePlot.
        print('ds')
        ds = MultiArrayDataSource(data=self.signals_data_model.data)

        self.signals_renderer.set(
            index=xs,
            yindex=ys,
            #index_mapper = LinearMapper(range=xrange), value_mapper = LinearMapper(range=yrange),
            value=ds,
            global_max=self.signals_data_model.data.max(),
            global_min=self.signals_data_model.data.min())
        self.signals_renderer.index_mapper.range = xrange
        self.signals_renderer.value_mapper.range = yrange
        self.signals_renderer.request_redraw()
コード例 #6
0
ファイル: ChacoQWidget.py プロジェクト: spherik/meg
    def _signals_renderer_default(self):
        print('_signals_renderer_default')
        """Create the default MultiLinePlot instance."""

        xs = ArrayDataSource(self.signals_data_model.x_index,
                             sort_order='ascending')
        xrange = DataRange1D()
        xrange.add(xs)

        ys = ArrayDataSource(self.signals_data_model.y_index,
                             sort_order='ascending')
        yrange = DataRange1D()
        yrange.add(ys)

        # The data source for the MultiLinePlot.
        ds = MultiArrayDataSource(data=self.signals_data_model.data)

        multi_line_plot_renderer = \
            MultiLinePlot(
                index = xs,
                yindex = ys,
                index_mapper = LinearMapper(range=xrange),
                value_mapper = LinearMapper(range=yrange),
                value=ds,
                global_max = self.signals_data_model.data.max(),
                global_min = self.signals_data_model.data.min(),
                fast_clip = False)

        # Add pan tool
        multi_line_plot_renderer.tools.append(
            PanTool(multi_line_plot_renderer, restrict_to_data=True))

        # Add zoom tool
        multi_line_plot_renderer.overlays.append(
            ZoomTool(multi_line_plot_renderer,
                     tool_mode="range",
                     always_on=False,
                     x_max_zoom_factor=20.0,
                     y_max_zoom_factor=20.0,
                     x_min_zoom_factor=1.0,
                     y_min_zoom_factor=1.0,
                     zoom_to_mouse=True))
        #multi_line_plot_renderer.overlays.append(LineInspector(multi_line_plot_renderer, axis="index",write_metadata=True,is_listener=True))
        # multi_line_plot_renderer.overlays.append(LineInspector(multi_line_plot_renderer, axis='value',
        #                                         write_metadata=True,
        #                                         is_listener=True))
        multi_line_plot_renderer.overlays.append(
            LineInspector(multi_line_plot_renderer,
                          axis="index",
                          write_metadata=True,
                          is_listener=True))
        return multi_line_plot_renderer
コード例 #7
0
def get_multiline_plot():
    prng = np.random.RandomState(seed=1234)

    x = np.linspace(0, 10, 50)
    y_data = np.column_stack([
        x**2,
        50 * np.sin(x),
        50 * np.cos(x),
        0.5 * x**2 + 2 * prng.randn(50),
        0.7 * x**2 + prng.randn(50),
    ])

    # data sources for the two axes
    xs = ArrayDataSource(np.arange(50))
    ys = ArrayDataSource(np.arange(y_data.shape[1]))
    y_range = DataRange1D(low=-0.5, high=y_data.shape[1] - 0.5)
    y_mapper = LinearMapper(range=y_range)

    # data source for the multiple lines
    lines_source = MultiArrayDataSource(data=y_data.T)

    colors = ['blue', 'green', 'yellow', 'orange', 'red']

    def color_generator(color_idx):
        return color_table[colors[color_idx]]

    multiline_plot = MultiLinePlot(
        index=xs,
        yindex=ys,
        index_mapper=LinearMapper(range=DataRange1D(xs)),
        value_mapper=y_mapper,
        value=lines_source,
        normalized_amplitude=1.0,
        use_global_bounds=False,
        color_func=color_generator,
        **PLOT_DEFAULTS)

    add_axes(multiline_plot, x_label='Days', y_label='Stock price changes')

    y_grid = PlotGrid(mapper=y_mapper,
                      orientation="horizontal",
                      line_style="dot",
                      component=multiline_plot)
    multiline_plot.overlays.append(y_grid)

    return multiline_plot
コード例 #8
0
def get_multiline_plot():
    prices = datasets.fetch_mldata('regression-datasets stock')

    T, N_LINES = 70, 5

    prices_data = prices['data'][:T, :N_LINES]
    prices_data -= prices_data[0, :]

    # data sources for the two axes
    xs = ArrayDataSource(np.arange(T))
    ys = ArrayDataSource(np.arange(N_LINES))
    y_range = DataRange1D(low=-0.5, high=N_LINES - 0.5)
    y_mapper = LinearMapper(range=y_range)

    # data source for the multiple lines
    lines_source = MultiArrayDataSource(data=prices_data.T)

    colors = ['blue', 'green', 'yellow', 'orange', 'red']

    def color_generator(color_idx):
        return color_table[colors[color_idx]]

    multiline_plot = MultiLinePlot(
        index=xs,
        yindex=ys,
        index_mapper=LinearMapper(range=DataRange1D(xs)),
        value_mapper=y_mapper,
        value=lines_source,
        normalized_amplitude=1.0,
        use_global_bounds=False,
        color_func=color_generator,
        **PLOT_DEFAULTS)

    add_axes(multiline_plot, x_label='Days', y_label='Stock price changes')

    y_grid = PlotGrid(mapper=y_mapper,
                      orientation="horizontal",
                      line_style="dot",
                      component=multiline_plot)
    multiline_plot.overlays.append(y_grid)

    return multiline_plot