colors
: Colors and colormap¶
This module provides API to manage colors.
-
silx.gui.colors.
rgba
(color, colorDict=None)[source]¶ Convert color code ‘#RRGGBB’ and ‘#RRGGBBAA’ to (R, G, B, A)
It also convert RGB(A) values from uint8 to float in [0, 1] and accept a QColor as color argument.
Parameters: - color (str) – The color to convert
- colorDict (dict) – A dictionary of color name conversion to color code
Returns: RGBA colors as floats in [0., 1.]
Return type: tuple
-
silx.gui.colors.
cursorColorForColormap
(colormapName)[source]¶ Get a color suitable for overlay over a colormap.
Parameters: colormapName (str) – The name of the colormap. Returns: Name of the color. Return type: str
-
silx.gui.colors.
DEFAULT_COLORMAPS
= ('gray', 'reversed gray', 'temperature', 'red', 'green', 'blue')¶ Tuple of supported colormap names.
-
silx.gui.colors.
DEFAULT_MIN_LIN
= 0¶ Default min value if in linear normalization
-
silx.gui.colors.
DEFAULT_MAX_LIN
= 1¶ Default max value if in linear normalization
-
silx.gui.colors.
DEFAULT_MIN_LOG
= 1¶ Default min value if in log normalization
-
silx.gui.colors.
DEFAULT_MAX_LOG
= 10¶ Default max value if in log normalization
-
class
silx.gui.colors.
Colormap
(name='gray', colors=None, normalization='linear', vmin=None, vmax=None)[source]¶ Description of a colormap
Parameters: - name (str) – Name of the colormap
- colors (tuple) – 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 (str) – Normalization: ‘linear’ (default) or ‘log’
- vmin (float) – Lower bound of the colormap or None for autoscale (default)
- vmax (float) – Upper bounds of the colormap or None for autoscale (default)
-
LINEAR
= 'linear'¶ constant for linear normalization
-
LOGARITHM
= 'log'¶ constant for logarithmic normalization
-
NORMALIZATIONS
= ('linear', 'log')¶ Tuple of managed normalizations
-
sigChanged
¶ Signal emitted when the colormap has changed.
-
getNColors
(nbColors=None)[source]¶ Returns N colors computed by sampling the colormap regularly.
Parameters: nbColors (int or None) – The number of colors in the returned array or None for the default value. The default value is 256 for colormap with a name (see setName()
) and it is the size of the LUT for colormap defined withsetColormapLUT()
.Returns: 2D array of uint8 of shape (nbColors, 4) Return type: numpy.ndarray
-
setName
(name)[source]¶ Set the name of the colormap to use.
Parameters: name (str) – 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
()[source]¶ Return the list of colors for the colormap or None if not set
Returns: the list of colors for the colormap or None if not set Return type: numpy.ndarray or None
-
setColormapLUT
(colors)[source]¶ Set the colors of the colormap.
Parameters: colors (numpy.ndarray) – the colors of the LUT. If float, it is converted from [0, 1] to uint8 range. Otherwise it is casted to uint8.
-
getNormalization
()[source]¶ Return the normalization of the colormap (‘log’ or ‘linear’)
Returns: the normalization of the colormap Return type: str
-
setNormalization
(norm)[source]¶ Set the norm (‘log’, ‘linear’)
Parameters: norm (str) – the norm to set
-
getVMin
()[source]¶ Return the lower bound of the colormap
Returns: the lower bound of the colormap Return type: float or None
-
setVMin
(vmin)[source]¶ Set the minimal value of the colormap
Parameters: vmin (float) – Lower bound of the colormap or None for autoscale (default) value)
-
getVMax
()[source]¶ Return the upper bounds of the colormap or None
Returns: the upper bounds of the colormap or None Return type: float or None
-
setVMax
(vmax)[source]¶ Set the maximal value of the colormap
Parameters: vmax (float) – Upper bounds of the colormap or None for autoscale (default)
-
isEditable
()[source]¶ Return if the colormap is editable or not
Returns: editable state of the colormap :rtype: bool
-
setEditable
(editable)[source]¶ Set the editable state of the colormap
Parameters: editable (bool) – is the colormap editable
-
getColormapRange
(data=None)[source]¶ Return (vmin, vmax)
Returns: the tuple vmin, vmax fitting vmin, vmax, normalization and data if any given Return type: tuple
-
setVRange
(vmin, vmax)[source]¶ Set the bounds of the colormap
Parameters: - vmin – Lower bound of the colormap or None for autoscale (default)
- vmax – Upper bounds of the colormap or None for autoscale (default)
-
copy
()[source]¶ Return a copy of the Colormap.
Return type: silx.gui.colors.Colormap
-
applyToData
(data)[source]¶ Apply the colormap to the data
Parameters: data (numpy.ndarray) – The data to convert.
-
static
getSupportedColormaps
()[source]¶ 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’) :rtype: tuple
-
silx.gui.colors.
preferredColormaps
()[source]¶ Returns the name of the preferred colormaps.
This list is used by widgets allowing to change the colormap like the
ColormapDialog
as a subset of colormap choices.Return type: tuple of str
-
silx.gui.colors.
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 (iterable of str) – Not empty list of colormap names Raises: ValueError – if the list of available preferred colormaps is empty.