How to use the chaco.linear_mapper.LinearMapper 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 / chaco / plot.py View on Github external
self.value_range.add(min, bar_min, center, bar_max, max)
        self.index_range.add(index)

        if styles.get("bar_color") == "auto" or styles.get("color") == "auto":
            self._auto_color_idx = \
                (self._auto_color_idx + 1) % len(self.auto_colors)
            styles["color"] = self.auto_colors[self._auto_color_idx]

        if self.index_scale == "linear":
            imap = LinearMapper(range=self.index_range,
                        stretch_data=self.index_mapper.stretch_data)
        else:
            imap = LogMapper(range=self.index_range,
                        stretch_data=self.index_mapper.stretch_data)
        if self.value_scale == "linear":
            vmap = LinearMapper(range=self.value_range,
                        stretch_data=self.value_mapper.stretch_data)
        else:
            vmap = LogMapper(range=self.value_range,
                        stretch_data=self.value_mapper.stretch_data)

        cls = self.renderer_map["candle"]
        plot = cls(index = index,
                          min_values = min,
                          bar_min = bar_min,
                          center_values = center,
                          bar_max = bar_max,
                          max_values = max,
                          index_mapper = imap,
                          value_mapper = vmap,
                          orientation = self.orientation,
                          origin = self.origin,
github enthought / chaco / examples / user_guide / plot_types / create_plot_snapshots.py View on Github external
def _1D_mapper(source):
        data_range = DataRange1D()
        data_range.add(source)
        return LinearMapper(range=data_range)
github enthought / chaco / examples / user_guide / plot_types / create_plot_snapshots.py View on Github external
means = y_with_noise.mean(0)
    stds = y_with_noise.std(0)

    x, y = get_data_sources(x=x, y=means)

    low = ArrayDataSource(means - stds)
    high = ArrayDataSource(means + stds)

    x_range = DataRange1D(low=0, high=6)
    y_range = DataRange1D(tight_bounds=False)
    y_range.add(y, low, high)

    errorbar_plot = ErrorBarPlot(
        index=x, value=y,
        index_mapper=LinearMapper(range=x_range),
        value_mapper=LinearMapper(range=y_range),
        value_low=low,
        value_high=high,
        endcap_size=11.,
        **PLOT_DEFAULTS
    )

    add_axes(errorbar_plot, x_label='Test values', y_label='Measured')

    return errorbar_plot
github enthought / chaco / chaco / plot.py View on Github external
sm.map(self._get_or_create_datasource, data)
            self.value_range.add(min, bar_min, bar_max, max)
            center = None
        elif len(data) == 6:
            index, min, bar_min, center, bar_max, max = \
                sm.map(self._get_or_create_datasource, data)
            self.value_range.add(min, bar_min, center, bar_max, max)
        self.index_range.add(index)

        if styles.get("bar_color") == "auto" or styles.get("color") == "auto":
            self._auto_color_idx = \
                (self._auto_color_idx + 1) % len(self.auto_colors)
            styles["color"] = self.auto_colors[self._auto_color_idx]

        if self.index_scale == "linear":
            imap = LinearMapper(range=self.index_range,
                        stretch_data=self.index_mapper.stretch_data)
        else:
            imap = LogMapper(range=self.index_range,
                        stretch_data=self.index_mapper.stretch_data)
        if self.value_scale == "linear":
            vmap = LinearMapper(range=self.value_range,
                        stretch_data=self.value_mapper.stretch_data)
        else:
            vmap = LogMapper(range=self.value_range,
                        stretch_data=self.value_mapper.stretch_data)

        cls = self.renderer_map["candle"]
        plot = cls(index = index,
                          min_values = min,
                          bar_min = bar_min,
                          center_values = center,
github enthought / chaco / chaco / plot.py View on Github external
Which corner the origin of this plot should occupy:
                "bottom left", "top left", "bottom right", "top right"
        **kwds :
            Additional keywords to pass to the factory.
        """
        if name is None:
            name = self._make_new_plot_name()
        if origin is None:
            origin = self.default_origin
        index = self._get_or_create_datasource(index_name)
        self.index_range.add(index)
        value = self._get_or_create_datasource(value_name)
        self.value_range.add(value)

        if self.index_scale == "linear":
            imap = LinearMapper(range=self.index_range)
        else:
            imap = LogMapper(range=self.index_range)
        if self.value_scale == "linear":
            vmap = LinearMapper(range=self.value_range)
        else:
            vmap = LogMapper(range=self.value_range)

        renderer = renderer_factory(
            index = index,
            value = value,
            index_mapper = imap,
            value_mapper = vmap,
            orientation = self.orientation,
            origin = origin,
            **kwds
        )
github enthought / chaco / chaco / plot.py View on Github external
-------
        [renderers] -> list of renderers created in response to this call.
        """
        if name is None:
            name = self._make_new_plot_name()
        if origin is None:
            origin = self.default_origin

        index, value, vectors = list(sm.map(self._get_or_create_datasource, data))

        self.index_range.add(index)
        self.value_range.add(value)

        imap = LinearMapper(range=self.index_range,
                            stretch_data=self.index_mapper.stretch_data)
        vmap = LinearMapper(range=self.value_range,
                            stretch_data=self.value_mapper.stretch_data)

        cls = self.renderer_map["quiver"]
        plot = cls(index = index,
                   value = value,
                   vectors = vectors,
                   index_mapper = imap,
                   value_mapper = vmap,
                   name = name,
                   origin = origin,
                   **styles
                   )
        self.add(plot)
        self.plots[name] = [plot]
        return [plot]
github enthought / chaco / examples / user_guide / plot_types / create_plot_snapshots.py View on Github external
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
github enthought / chaco / chaco / plot.py View on Github external
def _index_scale_changed(self, old, new):
        if old is None: return
        if new == old: return
        if not self.range2d: return
        if self.index_scale == "linear":
            imap = LinearMapper(range=self.index_range,
                                screen_bounds=self.index_mapper.screen_bounds,
                                stretch_data=self.index_mapper.stretch_data)
        else:
            imap = LogMapper(range=self.index_range,
                             screen_bounds=self.index_mapper.screen_bounds,
                             stretch_data=self.index_mapper.stretch_data)
        self.index_mapper = imap
        for key in self.plots:
            for plot in self.plots[key]:
                if not isinstance(plot, BaseXYPlot):
                    raise ValueError("log scale only supported on XY plots")
                if self.index_scale == "linear":
                    imap = LinearMapper(range=plot.index_range,
                                screen_bounds=plot.index_mapper.screen_bounds,
                                stretch_data=self.index_mapper.stretch_data)
                else:
github NMGRL / pychron / pychron / pipeline / plot / overlays / base_inset.py View on Github external
def __init__(self, xs, ys, index_bounds=None, value_bounds=None, *args, **kw):
        index = ArrayDataSource(xs)
        value = ArrayDataSource(ys)
        if index_bounds is not None:
            index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])
        else:
            index_range = DataRange1D()
        index_range.add(index)
        index_mapper = LinearMapper(range=index_range)
        index_range.tight_bounds = False
        if value_bounds is not None:
            value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])
        else:
            value_range = DataRange1D()
        value_range.add(value)
        value_mapper = LinearMapper(range=value_range)
        value_range.tight_bounds = False

        self.index = index
        self.value = value
        self.index_mapper = index_mapper
        self.value_mapper = value_mapper
        # self.color = "red"
        # self.line_width = 1.0
        # self.line_style = "solid"
github enthought / chaco / chaco / grid_mapper.py View on Github external
# be passed in at construction time.
        self.range = range

        if "_xmapper" not in kwargs:
            if x_type == "linear":
                self._xmapper = LinearMapper(range=self.range.x_range)
            elif x_type == "log":
                self._xmapper = LogMapper(range=self.range.x_range)
            else:
                raise ValueError("Invalid x axis type: %s" % x_type)
        else:
            self._xmapper = kwargs.pop("_xmapper")

        if "_ymapper" not in kwargs:
            if y_type == "linear":
                self._ymapper = LinearMapper(range=self.range.y_range)
            elif y_type == "log":
                self._ymapper = LogMapper(range=self.range.y_range)
            else:
                raise ValueError("Invalid y axis type: %s" % y_type)
        else:
            self._ymapper = kwargs.pop("_ymapper")

        # Now that the mappers are created, we can go to the normal HasTraits
        # constructor, which might set values that depend on us having a valid
        # range and mappers.
        super(GridMapper, self).__init__(**kwargs)