Color mapping of a range of values.
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.
Methods
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 with exp in the range minval..midval and with exp2 in the range midval..maxval.
Methods
ColorScale objects have the following methods:
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 were 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.
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.
A colorlegend is a colorscale divided in a number of subranges.
Methods
Create a color legend dividing a colorscale in n subranges.
The full value range of the colorscale is divided in n subranges, each half range being divided in n/2 subranges. This sets n+1 limits of the subranges. The n colors of the subranges correspond to the subrange middle value.
Methods
ColorLegend objects have the following methods:
Return the color representing a value val.
The color is that of the subrange holding the value. If the value matches a subrange limit, the lower range color is returned. If the value falls outside the colorscale range, a runtime error is raised, unless the corresponding underflowcolor or overflowcolor attribute has been set, in which case this attirbute is returned. Though these attributes can be set to any not None value, it will usually be set to some color value, that will be used to show overflow values. The returned color is a tuple of three RGB values in the range 0-1.