8.11.1 ColorScale class: Mapping floating point values into colors.

A colorscale maps floating point values within a certain range into colors and can be used to provide visual representation of numerical values. This is e.g. quite useful in Finite Element postprocessing (see the postproc plugin).

The ColorLegend class provides a way to make the ColorScale visible on the canvas.

The ColorScale class has this constructor:

class ColorScale( palet,minval=0.,maxval=1.,midval=None,exp=1.0,exp2=None)
Create a colorscale to map a range of values into colors.

The values range from minval to maxval (default 0.0..1.0).

A midval may be specified to set the value corresponding to the midle of the color scale. It defaults to the middle value of the range. It is especially useful if the range extends over negative and positive values to set 0.0 as the middle value.

The palet is a list of 3 colors, corresponding to the minval, midval and maxval respectively. The middle color may be given as None, in which case it will be set to the middle color between the first and last.

The Palette variable provides some useful predefined palets. You will hardly ever need to define your own palets.

The mapping function between numerical and color values is by default linear. Nonlinear mappings can be obtained by specifying an exponent 'exp' different from 1.0. Mapping is done with the 'stuur' function from the 'utils' module. If 2 exponents are given, mapping is done independently e with exp in the range minval..midval and with exp2 in the range midval..maxval.

ColorScale objects have the following methods:

scale( val)
Scale a value to the range -1...1.

If the ColorScale has only one exponent, values in the range mival..maxval are scaled to the range -1..+1.

If two exponents wer specified, scaling is done independently in one of the intervals minval..midval or midval..maxval resulting into resp. the interval -1..0 or 0..1.

color( val)
Return the color representing a value val.

The returned color is a tuple of three RGB values in the range 0-1. The color is obtained by first scaling the value to the -1..1 range using the 'scale' method, and then using that result to pick a color value from the palet. A palet specifies the three colors corresponding to the -1, 0 and 1 values.