### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >

# 16. `colorscale` — Color mapping of a range of values.

`Classes defined in module colorscale`

class `colorscale.``ColorScale`(palet='RAINBOW', minval=0.0, maxval=1.0, midval=None, exp=1.0, exp2=None)

  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.

  `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 were specified, scaling is done independently in the intervals minval..midval and midval..maxval, mapped resp. using exp2 and exp onto the intevals -1..0 and 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.

class `colorscale.``ColorLegend`(colorscale, n)

  A colorlegend divides a in a number of subranges.

  Parameters:

  - colorscale: a `ColorScale` instance
  - n: a positive integer

  For a `ColorScale` without `midval`, the full range is divided in `n` subranges; for a scale with `midval`, each of the two ranges is divided in `n/2` subranges. In each case the legend has `n` subranges limited by `n+1` values. The `n` colors of the legend correspond to the middle value of each subrange.

  `overflow`(oflow=None)

    Raise a runtime error if oflow == None, else return oflow.

  `color`(val)

    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.

`Functions defined in module colorscale`

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >