API References
Python package colourmap generates an N unique colors from the specified input colormap.
- colourmap.colourmap.check_logger(verbose: [<class 'str'>, <class 'int'>] = 'info')
Check the logger.
- colourmap.colourmap.convert_verbose_to_new(verbose)
Convert old verbosity to the new one.
- colourmap.colourmap.disable_tqdm()
Set the logger for verbosity messages.
- colourmap.colourmap.fromlist(y, X=None, cmap='Set1', gradient=None, method='matplotlib', scheme='rgb', opaque_type='per_class', verbose='info')
Generate colors from input list.
This function creates unique colors based on the input list y and the cmap. When the gradient hex color is defined, such as ‘#000000’, a gradient coloring space is created between two colors.
The start color of the particular y, using the cmap and The end color is the defined gradient, such as ‘#000000’.
- Parameters:
y (list of strings or integers) – For each unique value, a unique color is given back.
X (numpy array (optional)) – Coordinates for the x-axis and y-axis: [x, y]. Should be the same length of y. If X is provided, the gradient will be based on the density.
cmap (String, optional) – Colormap. The default is ‘Set1’.
gradient (String, (default: None)) – Hex color for the gradient based on the density. * None: Do not use gradient. * opaque: Towards the edges the points become more opaque and thus not visible. Note that scheme must be ‘rgb’ * ‘#FFFFFF’: Towards the edges it smooths into this color.
method (String, optional) – Method to generate colors ‘matplotlib’ (default) ‘seaborn’
scheme (String, optional) – The output of color is in the scheme: ‘rgb’ ‘hex’
opaque_type (String, optional) –
- Method to generate transparency. Requires scheme=’rgb’ and input data X
’per_class’: Transprancy is determined on the density within the class label (y)
’all’: Transprancy is determined on all available data points
’lineair’: Transprancy is lineair set within the class label (y)
verbose (int, (default: 'info')) – Print progress to screen. The default is ‘info’ 60: None, 40: error, 30: warning, 20: info, 10: debug
- Returns:
List of colors in the same order as y. dict for the unique colors
- Return type:
tuple containing
Examples
>>> import colourmap as cm >>> # Compute colors per class >>> y=[1,1,2,2,3,1,2,3] >>> rgb, colordict = cm.fromlist(y)
References
- colourmap.colourmap.generate(N, cmap='Set1', method='matplotlib', keep_alpha=False, scheme='rgb', verbose='info')
Generate N RGB colors for cmap.
- Parameters:
N (Integer) – Number of colors to be generated.
cmap (String, optional) – ‘Set1’ (default) ‘Set2’ ‘rainbow’ ‘bwr’ Blue-white-red ‘binary’ or ‘binary_r’ ‘seismic’ Blue-white-red ‘Blues’ white-to-blue ‘Reds’ white-to-red ‘Pastel1’ Discrete colors ‘Paired’ Discrete colors ‘Set1’ Discrete colors
method (String, optional) – Method to generate colors ‘matplotlib’ (default) ‘seaborn’
scheme (String, optional) – The output of color is in the scheme: ‘rgb’ ‘hex’
verbose (int, (default: 'info')) – Print progress to screen. The default is ‘info’ 60: None, 40: error, 30: warning, 20: info, 10: debug
References
Colormap: https://matplotlib.org/examples/color/colormaps_reference.html
- Returns:
color_list
- Return type:
numpy array with colors that range between [0-1, 0-1, 0-1].
- colourmap.colourmap.get_logger()
Return logger status.
- colourmap.colourmap.gradient_on_density_color(X, c_rgb, labels, opaque_type='per_class', showfig=False, verbose='info')
Set gradient on density color.
This function determines the density of the data and adds a transparency column. If samples are in dense areas, transparency values are towards 1 (visible), whereas isn none-dense areas, the transparency values are towards 0 (not visible).
- Parameters:
X (Array-like) – Input data to determine the density.
c_rgb (array-like of type Nx3 or Nx4) – RGB colors.
labels (list of labels with same size as X) – labels of the samples.
opaque_type (String, optional) –
‘per_class’: Transprancy is determined on the density within the class label (y)
’all’: Transprancy is determined on all available data points
’lineair’: Transprancy is lineair set within the class label (y)
showfig (Bool, default: False) – Show figure as sanity check.
verbose (int, (default: 'info')) – Print progress to screen. The default is ‘info’ 60: None, 40: error, 30: warning, 20: info, 10: debug
- Returns:
c_rgb – RGB for which the last column is the transparency.
- Return type:
array-like of Nx4
- colourmap.colourmap.hex2rgb(colors)
Convert hex color-range to RGB.
- Parameters:
colors (list) – list of str.
- Return type:
list of rgb colors.
- colourmap.colourmap.hex2rgba(colors)
Convert hex color-range to RGBA.
- Parameters:
colors (list) – list of str.
- Return type:
list of rgb colors.
- colourmap.colourmap.is_hex_color(color, verbose='info')
Check whether the input is a valid hex color code.
- verboseint, (default: ‘info’)
Print progress to screen. The default is ‘info’ 60: None, 40: error, 30: warning, 20: info, 10: debug
- colourmap.colourmap.linear_gradient(start_hex, finish_hex='#FFFFFF', n=10)
Return a gradient list of (n) colors between two hex colors.
start_hex and finish_hex should be the full six-digit color string, inlcuding the number sign (“#FFFFFF”)
- Parameters:
start_hex (str) – Hex starting color.
finish_hex (str, optional) – Hex end color. The default is “#FFFFFF”.
n (int, (default: 10)) – Spacing between start-stop colors.
- Returns:
lineair spacing.
- Return type:
dict
Examples
>>> import colourmap as cm >>> # Compute linear gradient for 10 points between black and white >>> colors = cm.linear_gradient("#000000", finish_hex="#FFFFFF", n=10)
- colourmap.colourmap.rgb2hex(colors, keep_alpha=False)
Convert RGB color-range to hex.
- Parameters:
colors (list) – list of floats that range between [0-1, 0-1, 0-1].
keep_alpha (bool, optional) – Keep the alpha value, which is the first number in RGB range. The default is False.
- Return type:
list of hex colors.
- colourmap.colourmap.set_logger(verbose: [<class 'str'>, <class 'int'>] = 'info')
Set the logger for verbosity messages.
- Parameters:
verbose ([str, int], default is 'info' or 20) – Set the verbose messages using string or integer values. * [0, 60, None, ‘silent’, ‘off’, ‘no’]: No message. * [10, ‘debug’]: Messages from debug level and higher. * [20, ‘info’]: Messages from info level and higher. * [30, ‘warning’]: Messages from warning level and higher. * [50, ‘critical’, ‘error’]: Messages from critical level and higher.
- Returns:
None.
> # Set the logger to warning
> set_logger(verbose=’warning’)
> # Test with different messages
> logger.debug(“Hello debug”)
> logger.info(“Hello info”)
> logger.warning(“Hello warning”)
> logger.critical(“Hello critical”)