colors: Colors and colormap#
This module provides API to manage colors.
- DEFAULT_MIN_LIN = 0#
Default min value if in linear normalization
- DEFAULT_MAX_LIN = 1#
Default max value if in linear normalization
- rgba(color, colorDict=None, colors=None)[source]#
Convert different kind of color definition to a tuple (R, G, B, A) of floats.
It supports: - color names: e.g., ‘green’ - color codes: ‘#RRGGBB’ and ‘#RRGGBBAA’ - indexed color names: e.g., ‘C0’ - RGB(A) sequence of uint8 in [0, 255] or float in [0, 1] - QColor
- Parameters:
color (Download Windows installer) – The color to convert
colorDict (Download Windows installer) – A dictionary of color name conversion to color code
colors (Download Windows installer) – Sequence of colors to use for `
- Return type:
- Returns:
RGBA colors as floats in [0., 1.]
- Raises:
ValueError – if the input is not a valid color
- greyed(color, colorDict=None)[source]#
Convert color code ‘#RRGGBB’ and ‘#RRGGBBAA’ to a grey color (R, G, B, A).
It also supports RGB(A) from uint8 in [0, 255], float in [0, 1], and QColor as color argument.
- Parameters:
color (Download Windows installer) – The color to convert
colorDict (Download Windows installer) – A dictionary of color name conversion to color code
- Return type:
- Returns:
RGBA colors as floats in [0., 1.]
- asQColor(color)[source]#
Convert color code ‘#RRGGBB’ and ‘#RRGGBBAA’ to a qt.QColor.
It also supports RGB(A) from uint8 in [0, 255], float in [0, 1], and QColor as color argument.
- Parameters:
color (Download Windows installer) – The color to convert
- Return type:
- cursorColorForColormap(colormapName)[source]#
Get a color suitable for overlay over a colormap.
- Parameters:
colormapName (Download Windows installer) – The name of the colormap.
- Return type:
- Returns:
Name of the color.
- class Colormap(name=None, colors=None, normalization='linear', vmin=None, vmax=None, autoscaleMode='minmax')[source]#
Description of a colormap
If no name nor colors are provided, a default gray LUT is used.
- Parameters:
name (Download Windows installer) – Name of the colormap
colors (Download Windows installer) – optional, custom colormap. Nx3 or Nx4 numpy array of RGB(A) colors, either uint8 or float in [0, 1]. If ‘name’ is None, then this array is used as the colormap.
normalization (Download Windows installer) – Normalization: ‘linear’ (default) or ‘log’
vmin (Download Windows installer) – Lower bound of the colormap or None for autoscale (default)
vmax (Download Windows installer) – Upper bounds of the colormap or None for autoscale (default)
autoscaleMode (Download Windows installer) –
- LINEAR = 'linear'#
constant for linear normalization
- LOGARITHM = 'log'#
constant for logarithmic normalization
- SQRT = 'sqrt'#
constant for square root normalization
- GAMMA = 'gamma'#
Constant for gamma correction normalization
- ARCSINH = 'arcsinh'#
constant for inverse hyperbolic sine normalization
- NORMALIZATIONS = ('linear', 'log', 'sqrt', 'gamma', 'arcsinh')#
Tuple of managed normalizations
- MINMAX = 'minmax'#
constant for autoscale using min/max data range
- STDDEV3 = 'stddev3'#
constant for autoscale using mean +/- 3*std(data) with a clamp on min/max of the data
- AUTOSCALE_MODES = ('minmax', 'stddev3')#
Tuple of managed auto scale algorithms
- sigChanged#
Signal emitted when the colormap has changed.
- setFromColormap(other)[source]#
Set this colormap using information from the other colormap.
- Parameters:
other (Download Windows installer) – Colormap to use as reference.
- getNColors(nbColors=None)[source]#
Returns N colors computed by sampling the colormap regularly.
- Parameters:
nbColors (Download Windows installer) – The number of colors in the returned array or None for the default value. The default value is the size of the colormap LUT.
- Return type:
- Returns:
2D array of uint8 of shape (nbColors, 4)
- setName(name)[source]#
Set the name of the colormap to use.
- Parameters:
name (Download Windows installer) – The name of the colormap. At least the following names are supported: ‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’, ‘jet’, ‘viridis’, ‘magma’, ‘inferno’, ‘plasma’.
- getColormapLUT(copy=True)[source]#
Return the list of colors for the colormap or None if not set.
This returns None if the colormap was set with
setName(). UsegetNColors()to get the colormap LUT for any colormap.- Parameters:
copy (Download Windows installer) – If true a copy of the numpy array is provided
- Return type:
- Returns:
the list of colors for the colormap or None if not set
- setColormapLUT(colors)[source]#
Set the colors of the colormap.
- Parameters:
colors (Download Windows installer) – the colors of the LUT. If float, it is converted from [0, 1] to uint8 range. Otherwise it is casted to uint8.
- setNaNColor(color)[source]#
Set the color to use for Not-A-Number floating point value.
- Parameters:
color (Download Windows installer) – RGB(A) color to use for NaN values
- getNormalization()[source]#
Return the normalization of the colormap.
See
setNormalization()for returned values.- Return type:
- Returns:
the normalization of the colormap
- setNormalization(norm)[source]#
Set the colormap normalization.
Accepted normalizations: ‘log’, ‘linear’, ‘sqrt’
- Parameters:
norm (Download Windows installer) – the norm to set
- setGammaNormalizationParameter(gamma)[source]#
Set the gamma correction parameter.
Only used for gamma correction normalization.
- Raises:
ValueError – If gamma is not valid
- Parameters:
gamma (Download Windows installer) –
- getGammaNormalizationParameter()[source]#
- Return type:
Returns the gamma correction parameter value.
- getAutoscaleMode()[source]#
- Return type:
Return the autoscale mode of the colormap (‘minmax’ or ‘stddev3’)
- setAutoscaleMode(mode)[source]#
Set the autoscale mode: either ‘minmax’ or ‘stddev3’
- Parameters:
mode (Download Windows installer) – the mode to set
- getVMin()[source]#
Return the lower bound of the colormap
- Return type:
- Returns:
the lower bound of the colormap
- setVMin(vmin)[source]#
Set the minimal value of the colormap
- Parameters:
vmin (Download Windows installer) – Lower bound of the colormap or None for autoscale (initial value)
- getVMax()[source]#
Return the upper bounds of the colormap or None
- Return type:
- Returns:
the upper bounds of the colormap or None
- setVMax(vmax)[source]#
Set the maximal value of the colormap
- Parameters:
vmax (Download Windows installer) – Upper bounds of the colormap or None for autoscale (initial value)
- isEditable()[source]#
Return if the colormap is editable or not
- Return type:
- Returns:
editable state of the colormap
- setEditable(editable)[source]#
Set the editable state of the colormap
- Parameters:
editable (Download Windows installer) – is the colormap editable
- getColormapRange(data=None)[source]#
Return (vmin, vmax) the range of the colormap for the given data or item.
- Parameters:
data (Download Windows installer) – The data or item to use for autoscale bounds.
- Return type:
- Returns:
(vmin, vmax) corresponding to the colormap applied to data if provided.
- getVRange()[source]#
Get the bounds of the colormap
- Return type:
- Returns:
A tuple of 2 values for min and max. Or None instead of float for autoscale
- setVRange(vmin, vmax)[source]#
Set the bounds of the colormap
- Parameters:
vmin (Download Windows installer) – Lower bound of the colormap or None for autoscale (default)
vmax (Download Windows installer) – Upper bounds of the colormap or None for autoscale (default)
- applyToData(data, reference=None)[source]#
Apply the colormap to the data
- Parameters:
data (Download Windows installer) – The data to convert or the item for which to apply the colormap.
reference (Download Windows installer) – The data or item to use as reference to compute autoscale
- Return type:
- static getSupportedColormaps()[source]#
- Return type:
Get the supported colormap names as a tuple of str.
The list should at least contain and start by:
(‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’, ‘viridis’, ‘magma’, ‘inferno’, ‘plasma’)
- restoreState(byteArray)[source]#
Read the colormap state from a QByteArray.
- Parameters:
byteArray (Download Windows installer) – Stream containing the state
- Return type:
- Returns:
True if the restoration sussseed
- preferredColormaps()[source]#
- Return type:
Returns the name of the preferred colormaps.
This list is used by widgets allowing to change the colormap like the
ColormapDialogas a subset of colormap choices.
- setPreferredColormaps(colormaps)[source]#
Set the list of preferred colormap names.
Warning: If a colormap name is not available it will be removed from the list.
- Parameters:
colormaps (Download Windows installer) – Not empty list of colormap names
- Raises:
ValueError – if the list of available preferred colormaps is empty.
- registerLUT(name, colors, cursor_color='black', preferred=True)[source]#
Register a custom LUT to be used with Colormap objects.
It can override existing LUT names.
- Parameters:
name (Download Windows installer) – Name of the LUT as defined to configure colormaps
colors (Download Windows installer) – The custom LUT to register. Nx3 or Nx4 numpy array of RGB(A) colors, either uint8 or float in [0, 1].
preferred (Download Windows installer) – If true, this LUT will be displayed as part of the preferred colormaps in dialogs.
cursor_color (Download Windows installer) – Color used to display overlay over images using colormap with this LUT.