Mappers

AbstractMapper

class chaco.api.AbstractMapper

Bases: traits.has_traits.HasTraits

Defines an abstract mapping from a region in input space to a region in output space.

Traits :

updated : Event

A generic “update” event that generally means that anything that relies on this mapper for visual output should do a redraw or repaint.

domain_limits : Tuple(None, None)

A tuple representing the minimum and maximum values of the domain (data space). The dimensionality of each value varies depending on the dimensions of the mapper, so for 1D mappers these will be scalars, for image and 2D mappers these will be tuples.

map_data(screen_val) → data_val

map_data(screen_val) -> data_val

Maps values from screen space into data space.

map_data_array(screen_vals) → data_vals

map_data_array(screen_vals) -> data_vals

Maps an array of values from screen space into data space. By default, this method just loops over the points, calling map_data() on each one. For vectorizable mapping functions, override this implmentation with a faster one.

map_screen(data_array) → screen_array

map_screen(data_array) -> screen_array

Maps values from data space into screen space.

Base1DMapper

class chaco.api.Base1DMapper

Bases: chaco.abstract_mapper.AbstractMapper

Defines an abstract mapping from a 1-D region in input space to a 1-D region in output space.

Traits :

range : Instance(DataRange1D)

The data-space bounds of the mapper.

low_pos : Float(0.0)

The screen space position of the lower bound of the data space.

high_pos : Float(1.0)

The screen space position of the upper bound of the data space.

screen_bounds : Property

Convenience property to get low and high positions in one structure. Must be a tuple (low_pos, high_pos).

stretch_data : Bool(True)

Should the mapper stretch the dataspace when its screen space bounds are modified (default), or should it preserve the screen-to-data ratio and resize the data bounds? If the latter, it will only try to preserve the ratio if both screen and data space extents are non-zero.

sign : Property

The sign of the mapping: 1 if deltas match sign, -1 if opposite sign

LinearMapper

class chaco.api.LinearMapper

Bases: chaco.base_1d_mapper.Base1DMapper

Maps a 1-D data space to and from screen space by specifying a range in data space and a corresponding fixed line in screen space.

This class concerns itself only with metric and not with orientation. So, to “flip” the screen space orientation, simply swap the values for low_pos and high_pos.

map_data(screen_val) → data_val

map_data(screen_val) -> data_val

Overrides AbstractMapper. Maps values from screen space into data space.

map_data_array(screen_vals) → data_vals

map_data_array(screen_vals) -> data_vals

Overrides AbstractMapper. Maps an array of values from screen space into data space.

map_screen(data_array) → screen_array

map_screen(data_array) -> screen_array

Overrides AbstractMapper. Maps values from data space into screen space.

LogMapper

class chaco.api.LogMapper

Bases: chaco.base_1d_mapper.Base1DMapper

Defines a 1-D logarithmic scale mapping from a 1-D region in input space to a 1-D region in output space.

Traits :

fill_value : Float(1.0)

The value to map when asked to map values <= LOG_MINIMUM to screen space.

map_data(screen_val) → data_val

map_data(screen_val) -> data_val

Overrides Abstract Mapper. Maps values from screen space into data space.

map_screen(data_array) → screen_array

map_screen(data_array) -> screen_array

Overrides AbstractMapper. Maps values from data space to screen space.

GridMapper

class chaco.api.GridMapper(x_type='linear', y_type='linear', range=None, **kwargs)

Bases: chaco.abstract_mapper.AbstractMapper

Maps a 2-D data space to and from screen space by specifying a 2-tuple in data space or by specifying a pair of screen coordinates.

The mapper concerns itself only with metric and not with orientation. So, to “flip” a screen space orientation, swap the appropriate screen space values for x_low_pos, x_high_pos, y_low_pos, and y_high_pos.

Traits :

range : Instance(DataRange2D)

The data-space bounds of the mapper.

x_low_pos : Float(0.0)

The screen space position of the lower bound of the horizontal axis.

x_high_pos : Float(1.0)

The screen space position of the upper bound of the horizontal axis.

y_low_pos : Float(0.0)

The screen space position of the lower bound of the vertical axis.

y_high_pos : Float(1.0)

The screen space position of the upper bound of the vertical axis.

screen_bounds : Property

Convenience property for low and high positions in one structure. Must be a tuple (x_low_pos, x_high_pos, y_low_pos, y_high_pos).

stretch_data_x : DelegatesTo(‘_xmapper’, prefix=’stretch_data’)

Should the mapper stretch the dataspace when its screen space bounds are modified (default), or should it preserve the screen-to-data ratio and resize the data bounds? If the latter, it will only try to preserve the ratio if both screen and data space extents are non-zero.

stretch_data_y : DelegatesTo(‘_ymapper’, prefix=’stretch_data’)

maintain_aspect_ratio : Bool

Should the mapper try to maintain a fixed aspect ratio between x and y

aspect_ratio : Float(1.0)

The aspect ratio that we wish to maintain

map_data(screen_pts) → data_vals

map_data(screen_pts) -> data_vals

Maps values from screen space into data space.

map_screen(data_pts) → screen_array

map_screen(data_pts) -> screen_array

Maps values from data space into screen space.

ColorMapper

class chaco.api.ColorMapper(segmentdata, **kwtraits)

Bases: chaco.abstract_colormap.AbstractColormap

Represents a simple band-of-colors style of color map.

The look-up transfer function is a simple linear function between defined intensities. There is no limit to the number of steps that can be defined. If the segment intervals contain very few array locations, quantization errors will occur.

Construction of a ColorMapper can be done through the factory methods from_palette_array() and from_segment_map(). Do not make direct calls to the ColorMapper constructor.

Traits :

color_bands : Property(Array)

The color table.

steps : Int(256)

The total number of color steps in the map.

name : Str

The name of this color map.

low_pos : None

Not used.

high_pos : None

Not used.

updated : Event

A generic “update” event that generally means that anything that relies on this mapper for visual output should do a redraw or repaint.

classmethod from_file(filename, **traits)

Creates a ColorMapper from a file.

The filename parameter is the name of a file whose lines each contain 4 or 5 float values between 0.0 and 1.0. The first value is an offset in the range [0..1], and the remaining 3 or 4 values are red, green, blue, and optionally alpha values for the color corresponding to that offset.

The first line is assumed to contain the name of the colormap.

classmethod from_palette_array(palette, **traits)

Creates a ColorMapper from a palette array.

The palette colors are linearly interpolated across the range of mapped values.

The palette parameter is a Nx3 or Nx4 array of intensity values, where N > 1:

[[R0, G0, B0], ... [R(N-1), G(N-1), B(N-1)]]

[[R0, G0, B0, A0], ... [R(N-1), G(N-1), B(N-1), A(N-1]]
classmethod from_segment_map(segment_map, **traits)

Creates a Colormapper from a segment map.

The segment_map parameter is a dictionary with ‘red’, ‘green’, and ‘blue’ (and optionally ‘alpha’) entries. Each entry is a list of (x, y0, y1) tuples:

  • x: an offset in [0..1] (offsets within the list must be in ascending order)
  • y0: value for the color channel for values less than or equal to x
  • y1: value for the color channel for values greater than x

When a data value gets mapped to a color, it will be normalized to be within [0..1]. For each RGB(A) component, the two adjacent values will be found in the segment_map. The mapped component value will be found by linearly interpolating the two values.

Generally, y0==y1. Colormaps with sharp transitions will have y0!=y1 at the transitions.

map_index(ary)

Maps an array of values to their corresponding color band index.

map_screen(data_array)

Maps an array of data values to an array of colors.

map_uint8(data_array)

Maps an array of data values to an array of colors.

reverse_colormap()

Reverses the color bands of this colormap.

ColorMapTemplate

class chaco.api.ColorMapTemplate(colormap=None, **kwtraits)

Bases: traits.has_traits.HasTraits

A class representing the state of a ColorMapper, for use when persisting plots.

Traits :

segment_map : Any

The segment data of the color map.

steps : Int(256)

The number of steps in the color map.

range_low_setting : Trait(‘auto’, ‘auto’, Float)

Low end of the color map range.

range_high_setting : Trait(‘auto’, ‘auto’, Float)

High end of the color map range.

from_colormap(colormap)

Populates this template from a color map.

to_colormap(range=None)

Returns a ColorMapper instance from this template.

TransformColorMapper

class chaco.api.TransformColorMapper(segmentdata, **kwtraits)

Bases: chaco.color_mapper.ColorMapper

This class adds arbitrary data transformations to a ColorMapper.

The default ColorMapper is basically a linear mapper from data space to color space. A TransformColorMapper allows a nonlinear mapper to be created.

A ColorMapper works by linearly transforming the data from data space to the unit interval [0,1], and then linearly mapping that interval to the color space.

A TransformColorMapper allows an arbitrary transform to be inserted at two places in this process. First, an initial transformation, data_func can be applied to the data before is it mapped to [0,1]. Then another function, unit_func, can be applied to the transformed data on [0,1] before it is mapped to color space. Normally, a unit_func is map of the unit interval [0,1] to itself (e.g. x^2 or sin(pi*x/2)).

Traits :

data_func : Trait(None, None, Callable)

unit_func : Trait(None, None, Callable)

transformed_bounds : Tuple(Trait(None, None, Float), Trait(None, None, Float))

classmethod factory_from_color_map(color_map, data_func=None, unit_func=None, **traits)

Create a TransformColorMapper factory function from a standard colormap factory function.

WARNING: This function is untested; I realized I didn’t need it shortly after writing it, so I haven’t tried it yet. –WW

classmethod from_color_map(color_map, data_func=None, unit_func=None, **traits)

Create a TransformColorMapper from a colormap generator function.

The return value is an instance of TransformColorMapper, not a factory function, so this does not provide a direct replacement for a standard colormap factory function. For that, use the class method TransoformColorMapper.factory_from_color_map().

classmethod from_color_mapper(color_mapper, data_func=None, unit_func=None, **traits)

Create a TransformColorMapper from an existing ColorMapper instance.

map_index(data_array)

Maps an array of values to their corresponding color band index.

map_screen(data_array)

Maps an array of data values to an array of colors.

map_uint8(data_array)

Maps an array of data values to an array of colors.

Page Contents

This Page