How to use the chaco.api.ArrayDataSource 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 jonathanrocher / climate_model / Code / ml_chaco.py View on Github external
def gen_line_plot(series_one, series_two, y_axis_name=''):
    """
    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',
github jonathanrocher / climate_model / Code / timeseries.py View on Github external
from chaco.api import ArrayDataSource, LinearMapper, DataRange1D, VPlotContainer, \
                      FilledLinePlot, PlotGrid, PlotAxis, PlotLabel, \
                      Blues as cmap
from chaco.tools.api import PanTool
from chaco.scales.api import CalendarScaleSystem
from chaco.scales_tick_generator import ScalesTickGenerator

from chaco.horizon_plot import HorizonPlot, BandedMapper

class WeatherTimeseries(HasTraits):

    plot = Instance(Component)

    timeseries = Instance(pandas.DataFrame)

    index_ds = Instance(ArrayDataSource, dict(sort_order='none'))
    value_ds = List(ArrayDataSource)

    rows = List

    def _timeseries_changed(self, new):
        # Filter down to days
        cols = new.columns
        idx = [time.mktime(d.utctimetuple()) for d in new.index]
        self.index_ds.set_data(idx)
        vals = []
        self.rows = list(reversed(cols[2:-6:2]))
        for col in self.rows:
            data = new[col]
            vals.append(ArrayDataSource(data.view(numpy.ndarray)))
        
        self.value_ds = vals
github jonathanrocher / climate_model / Code / ml_chaco.py View on Github external
def gen_line_plot(series_one, series_two, y_axis_name=''):
    """
    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')
github enthought / chaco / examples / demo / multi_line_plot_demo.py View on Github external
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())
github enthought / chaco / examples / demo / financial_plot.py View on Github external
def _create_plot_component():

    # Create the data and datasource objects
    numpoints = 500
    index = arange(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",
                                alpha = 0.5,
                                bgcolor = "white",
                                border_visible = True)
    add_default_grids(price_plot)
github NMGRL / pychron / pychron / canvas / canvas2D / base_data_canvas.py View on Github external
def line_plot(self, x, y, new_plot=True):
        if self.plot is None or new_plot:
            if isinstance(x, (float, int)):
                x = [x]

            if isinstance(y, (float, int)):
                y = [y]

            self.plot = LinePlot(
                index=ArrayDataSource(x),
                value=ArrayDataSource(y),
                index_mapper=LinearMapper(range=self.index_range),
                value_mapper=LinearMapper(range=self.value_range))

            self.add(self.plot)
        else:

            datax = self.plot.index.get_data()
            datay = self.plot.value.get_data()
            nx = hstack((datax, [x]))
            ny = hstack((datay, [y]))

            self.plot.index.set_data(nx)
            self.plot.value.set_data(ny)
github enthought / chaco / examples / demo / tornado.py View on Github external
def _make_curves(self):
        (index_points, value_points) = self._get_points()
        size = len(index_points)

        middle_value=2500000.0
        mid_values=middle_value*ones(size)
        low_values=mid_values-10000.0*value_points
        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,
github enthought / chaco / chaco / shell / plot_maker.py View on Github external
# Make sure everything is a numpy array
    data = []
    for arg in args:
        if isinstance(arg, list) or isinstance(arg, tuple):
            data.append(array(arg))
        else:
            data.append(arg)

    if len(data) == 0:
        raise ChacoShellError, "Insufficient data for plot."

    # 1D array(s)
    if len(data[0].shape) == 1:
        if len(data) == 1:
            # Only a single array was provided
            index_ds = ArrayDataSource(arange(len(data[0])), sort_order="ascending")
            value_ds = ArrayDataSource(data[0], sort_order="none")
            return [(index_ds, value_ds)]

        else:
            # multiple arrays were provided
            index_ds = ArrayDataSource(data[0], sort_order=index_sort)
            return [(index_ds, ArrayDataSource(v, sort_order="none")) for v in data[1:]]

    # 2D arrays
    elif len(data[0].shape) == 2:
        sources = []
        # Loop over all the 2D arrays
        for ary in data:
            if ary.shape[0] > ary.shape[1]:
                index_ary = ary[:, 0]
                value_arrays = ary[:, 1:]
github enthought / chaco / examples / demo / advanced / cmap_variable_sized_scatter.py View on Github external
numpts = 1000
    x = numpy.arange(0, numpts)
    y = numpy.random.random(numpts)
    marker_size = numpy.random.normal(4.0, 4.0, numpts)
    color = numpy.random.random(numpts)

    # Create a plot data object and give it this data
    pd = ArrayPlotData()
    pd.set_data("index", x)
    pd.set_data("value", y)

    # Because this is a non-standard renderer, we can't call plot.plot, which
    # sets up the array data sources, mappers and default index/value ranges.
    # So, its gotta be done manually for now.

    index_ds = ArrayDataSource(x)
    value_ds = ArrayDataSource(y)
    color_ds = ArrayDataSource(color)

    # Create the plot
    plot = Plot(pd)
    plot.index_range.add(index_ds)
    plot.value_range.add(value_ds)

    # Create the index and value mappers using the plot data ranges
    imapper = LinearMapper(range=plot.index_range)
    vmapper = LinearMapper(range=plot.value_range)

    # Create the scatter renderer
    scatter = ColormappedScatterPlot(
                    index=index_ds,
                    value=value_ds,
github enthought / chaco / examples / demo / tornado.py View on Github external
def _make_curves(self):
        (index_points, value_points) = self._get_points()
        size = len(index_points)

        middle_value=2500000.0
        mid_values=middle_value*ones(size)
        low_values=mid_values-10000.0*value_points
        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,