How to use the chaco.api.DataRange1D function in chaco

To help you get started, we’ve selected a few chaco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / chaco / examples / financial / ohlc.py View on Github external
def _create_plot(self, times, prices):
        cls = self._renderer_map[self.plottype]
        if self.plot is None:
            index_mapper = LinearMapper(range=DataRange1D(times))
            value_mapper = LinearMapper(range=DataRange1D(prices))
        else:
            index_mapper = self.plot.index_mapper
            value_mapper = self.plot.value_mapper
        price_plot = cls(times = times, prices = prices,
                        index_mapper = index_mapper,
                        value_mapper = value_mapper,
                        bgcolor = "white",
                        border_visible = True)

        # Set the plot's bottom axis to use the Scales ticking system
        ticker = ScalesTickGenerator(scale=CalendarScaleSystem())
        bottom_axis = PlotAxis(price_plot, orientation="bottom",
                               tick_generator = ticker)
        price_plot.overlays.append(bottom_axis)
        price_plot.overlays.append(PlotAxis(price_plot, orientation="left"))
github jonathanrocher / climate_model / Code / timeseries.py View on Github external
def _rebuild_plot(self):
        container = self.plot
        
        value_range = DataRange1D(low=-1, high=1.)
        index_range = DataRange1D(self.index_ds, high='track', tracking_amount=24*3600*365)

        color_mapper = cmap(range=value_range)
    
        # Remove old plots
        container.remove(*container.components)
        for val, row in zip(self.value_ds, self.rows):
            horizon = HorizonPlot(
                index = self.index_ds,
                value = val,
                index_mapper = LinearMapper(range=index_range, stretch_data=False),
                value_mapper = BandedMapper(range=DataRange1D(val)),
                color_mapper = cmap(range=DataRange1D(val)), #color_mapper,
                negative_bands = False,
                )   
            horizon.tools.append(PanTool(horizon, constrain=True, constrain_direction="x"))
            horizon.overlays.append(PlotLabel(component=horizon, hjustify='right', text=row, overlay_position='outside left'))
github enthought / chaco / examples / demo / financial_plot_dates.py View on Github external
# In order for the date axis to work, the index data points need to
    # be in units of seconds since the epoch.  This is because we are using
    # the CalendarScaleSystem, whose formatters interpret the numerical values
    # as seconds since the epoch.
    numpoints = 500
    index = create_dates(numpoints)
    returns = random.lognormal(0.01, 0.1, size=numpoints)
    price = 100.0 * cumprod(returns)
    volume = abs(random.normal(1000.0, 1500.0, size=numpoints) + 2000.0)

    time_ds = ArrayDataSource(index)
    vol_ds = ArrayDataSource(volume, sort_order="none")
    price_ds = ArrayDataSource(price, sort_order="none")

    xmapper = LinearMapper(range=DataRange1D(time_ds))
    vol_mapper = LinearMapper(range=DataRange1D(vol_ds))
    price_mapper = LinearMapper(range=DataRange1D(price_ds))

    price_plot = FilledLinePlot(index = time_ds, value = price_ds,
                                index_mapper = xmapper,
                                value_mapper = price_mapper,
                                edge_color = "blue",
                                face_color = "paleturquoise",
                                bgcolor = "white",
                                border_visible = True)
    price_plot.overlays.append(PlotAxis(price_plot, orientation='left')),

    # Set the plot's bottom axis to use the Scales ticking system
    bottom_axis = PlotAxis(price_plot, orientation="bottom",# mapper=xmapper,
                    tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
    price_plot.overlays.append(bottom_axis)
    hgrid, vgrid = add_default_grids(price_plot)
github enthought / chaco / examples / demo / quiver.py View on Github external
# Create starting points for the vectors.
        numpts = self.numpts
        x = sort(random(numpts))
        y = random(numpts)

        # Create vectors.
        vectorlen = self.vectorlen
        vectors = array((random(numpts)*vectorlen, random(numpts)*vectorlen)).T

        # Create an array data sources to plot all vectors at once
        xs = ArrayDataSource(x, sort_order='ascending')
        ys = ArrayDataSource(y)
        vector_ds = MultiArrayDataSource(vectors)

        # Set up the Plot
        xrange = DataRange1D()
        xrange.add(xs)
        yrange = DataRange1D()
        yrange.add(ys)

        quiverplot = QuiverPlot(index = xs, value = ys,
                        vectors = vector_ds,
                        index_mapper = LinearMapper(range=xrange),
                        value_mapper = LinearMapper(range=yrange),
                        bgcolor = "white")

        add_default_axes(quiverplot)
        add_default_grids(quiverplot)

        # Attach some tools to the plot
        quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift"))
        zoom = ZoomTool(quiverplot)
github enthought / chaco / examples / financial / ohlc.py View on Github external
def _create_plot(self, times, prices):
        cls = self._renderer_map[self.plottype]
        if self.plot is None:
            index_mapper = LinearMapper(range=DataRange1D(times))
            value_mapper = LinearMapper(range=DataRange1D(prices))
        else:
            index_mapper = self.plot.index_mapper
            value_mapper = self.plot.value_mapper
        price_plot = cls(times = times, prices = prices,
                        index_mapper = index_mapper,
                        value_mapper = value_mapper,
                        bgcolor = "white",
                        border_visible = True)

        # Set the plot's bottom axis to use the Scales ticking system
        ticker = ScalesTickGenerator(scale=CalendarScaleSystem())
        bottom_axis = PlotAxis(price_plot, orientation="bottom",
                               tick_generator = ticker)
        price_plot.overlays.append(bottom_axis)
        price_plot.overlays.append(PlotAxis(price_plot, orientation="left"))
        hgrid, vgrid = add_default_grids(price_plot)
github jonathanrocher / climate_model / Code / timeseries.py View on Github external
def _rebuild_plot(self):
        container = self.plot
        
        value_range = DataRange1D(low=-1, high=1.)
        index_range = DataRange1D(self.index_ds, high='track', tracking_amount=24*3600*365)

        color_mapper = cmap(range=value_range)
    
        # Remove old plots
        container.remove(*container.components)
        for val, row in zip(self.value_ds, self.rows):
            horizon = HorizonPlot(
                index = self.index_ds,
                value = val,
                index_mapper = LinearMapper(range=index_range, stretch_data=False),
                value_mapper = BandedMapper(range=DataRange1D(val)),
                color_mapper = cmap(range=DataRange1D(val)), #color_mapper,
                negative_bands = False,
                )   
            horizon.tools.append(PanTool(horizon, constrain=True, constrain_direction="x"))
            horizon.overlays.append(PlotLabel(component=horizon, hjustify='right', text=row, overlay_position='outside left'))
            container.add(horizon)
        bottom_axis = PlotAxis(horizon, orientation="bottom",
                    tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
        container.overlays = [bottom_axis]

        container.request_redraw()
github enthought / chaco / examples / demo / basic / horizon_plot.py View on Github external
# In order for the date axis to work, the index data points need to
    # be in units of seconds since the epoch.  This is because we are using
    # the CalendarScaleSystem, whose formatters interpret the numerical values
    # as seconds since the epoch.
    high = 1.
    numpoints = 5000

    random.seed(1000)

    index = create_dates(numpoints)
    price = 100*cumprod(random.lognormal(0.0, 0.04, size=numpoints))
    changes = price/price[0] - 1.

    index_ds = ArrayDataSource(index)
    value_ds = ArrayDataSource(changes, sort_order="none")
    value_range = DataRange1D(value_ds, low=-high, high=high)
    
    index_mapper = LinearMapper(range=DataRange1D(index_ds), stretch_data=False)
    
    horizon = HorizonPlot(
            bands = 4,
            index = index_ds,
            value = value_ds,
            index_mapper = index_mapper,
            value_mapper = BandedMapper(range=DataRange1D(low=0, high=high)),
            color_mapper = cmap(range=value_range),
            )
    horizon.tools.append(PanTool(horizon, constrain=True, constrain_direction="x"))
    axis = PlotAxis(mapper = horizon.value_mapper, component=horizon, orientation="left",
                   tick_label_position="outside")
    horizon.overlays.append(axis)
github enthought / chaco / examples / demo / tornado.py View on Github external
high_values=mid_values+20000.0*value_points

        idx = ArrayDataSource(index_points)
        vals = ArrayDataSource(low_values, sort_order="none")

        idx2 = ArrayDataSource(index_points)
        vals2 = ArrayDataSource(high_values, sort_order="none")

        starting_vals = ArrayDataSource(mid_values, sort_order="none")

        # Create the index range
        index_range = DataRange1D(idx, low=0.5, high=9.5)
        index_mapper = LinearMapper(range=index_range)

        # Create the value range
        value_range = DataRange1D(vals, vals2, low_setting='auto',
                                  high_setting='auto', tight_bounds=False)
        value_mapper = LinearMapper(range=value_range,tight_bounds=False)

        # Create the plot
        plot1 = BarPlot(index=idx, value=vals,
                        value_mapper=value_mapper,
                        index_mapper=index_mapper,
                        starting_value=starting_vals,
                        line_color='black',
                        orientation='v',
                        fill_color=tuple(COLOR_PALETTE[6]),
                        bar_width=0.8, antialias=False)

        plot2 = BarPlot(index=idx2, value=vals2,
                        value_mapper=value_mapper,
                        index_mapper=index_mapper,
github jonathanrocher / climate_model / Code / ml_chaco.py View on Github external
Parameters
    ----------
    series_one : nd array
    series_two : nd array

    """

    size = min(series_one.shape[0],
        series_two.shape[0])

    idx = ArrayDataSource(arange(size))

    series_one_data = ArrayDataSource(series_one[:size])
    series_two_data = ArrayDataSource(series_two[:size])

    y_range = DataRange1D(series_one_data)
    y_range.tight_bounds = False
    y_range.margin = 50
    x_mapper = LinearMapper(range=DataRange1D(idx))
    y_mapper = LinearMapper(range=y_range)

    series_one_plot = LinePlot(index=idx,
        value=series_one_data, index_mapper=x_mapper,
        value_mapper=y_mapper, color='blue')

    series_two_plot = LinePlot(index=idx,
        value=series_two_data, index_mapper=x_mapper,
        value_mapper=y_mapper, color='red')

    container = OverlayPlotContainer(bgcolor='white',
        padding=25, fill_padding=False, border_visible=True)