scanpex.pl.preferences package
Module contents
- scanpex.pl.preferences.level_cmap(color=None, grayscale=0.2, gamma=2, name=None)[source]
Create a custom linear segmented colormap transitioning from grey to a color.
This function generates a colormap that starts at a specific shade of grey and interpolates linearly to the target color.
- Parameters:
color (tuple of float, optional) – The target RGBA color to transition to. By default None, assigning a specific purple-blue blend.
grayscale (float, optional) – The intensity of the starting grey color (passed to plt.cm.Greys). 0.0 is black, 1.0 is white. By default 0.2.
gamma (float, optional) – Gamma correction factor for the colormap. By default 2.
name (str, optional) – The name of the colormap. If None, generates a name based on the color. By default None.
- Returns:
The generated colormap object.
- Return type:
matplotlib.colors.LinearSegmentedColormap
- scanpex.pl.preferences.rgba2gray(r, g, b, a)[source]
Calculate the luminance of an RGBA color weighted by its alpha channel.
Uses the standard luminance formula (0.299R + 0.587G + 0.114B) adapted to the provided weights.
- Parameters:
r (float) – Red, Green, and Blue components (0.0 to 1.0).
g (float) – Red, Green, and Blue components (0.0 to 1.0).
b (float) – Red, Green, and Blue components (0.0 to 1.0).
a (float) – Alpha component (transparency).
- Returns:
The weighted luminance value.
- Return type:
float
- scanpex.pl.preferences.textcolor(c, thresh=0.4, dark='.2', light='1')[source]
Determine whether text should be light or dark based on background brightness.
Useful for ensuring text readability on varying background colors (e.g., in heatmaps or bar plots).
- Parameters:
c (str or tuple) – The background color. Can be a string representation of a float (e.g., “0.5” for grayscale) or an RGBA tuple.
thresh (float, optional) – The luminance threshold. If the calculated luminance of c is greater than this value, the background is considered “light”. By default 0.4.
dark (str, optional) – The color to return if the background is light. By default “.2” (dark grey).
light (str, optional) – The color to return if the background is dark. By default “1” (white).
- Returns:
The color code for the text (dark or light).
- Return type:
str