chaco.color_mapper module

Defines the ColorMapper and ColorMapTemplate classes.

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

Bases: traits.has_traits.HasTraits

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

from_colormap(colormap)

Populates this template from a color map.

range_high_setting = Union(Constant("auto"), Float)

High end of the color map range.

range_low_setting = Union(Constant("auto"), Float)

Low end of the color map range.

segment_map = Any

The segment data of the color map.

steps = Int(256)

The number of steps in the color map.

to_colormap(range=None)

Returns a ColorMapper instance from this template.

class chaco.color_mapper.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.

color_bands = Property(Array)

The color table.

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.

high_pos = None

Not used.

low_pos = None

Not used.

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.

name = Str

The name of this color map.

reverse_colormap()

Reverses the color bands of this colormap.

steps = Int(256)

The total number of color steps in the map.

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.