my_code_base.plot.colors

Functions

build_continuous_cmap(...)

Create and return a color map that can be used in heat map figures.

hex_to_rgb(→ tuple)

Convert hex to rgb colors

rgb_to_dec(→ tuple[float])

Convert rgb to decimal colours (i.e. divides each value by 255)

Module Contents

my_code_base.plot.colors.build_continuous_cmap(hex_list: list[str], float_list=None, N=256, name='my_cmap') matplotlib.colors.LinearSegmentedColormap[source]

Create and return a color map that can be used in heat map figures. If float_list is not provided, colour map graduates linearly between each color in hex_list. If float_list is provided, each color in hex_list is mapped to the respective location in float_list.

Source: https://towardsdatascience.com/beautiful-custom-colormaps-with-matplotlib-5bab3d1f0e72

Parameters:
hex_list : list of hex code strings

float_list : list of floats between 0 and 1, same length as hex_list. Must start with 0 and end with 1.

Return type:

colour map

my_code_base.plot.colors.hex_to_rgb(value: str) tuple[source]

Convert hex to rgb colors

Parameters:
value : string

String of 6 characters representing a hex colour.

Returns:

list length 3 of RGB values

Return type:

tuple

Examples

>>> hex_to_rgb('#f00')   # red
(255, 0, 0)
>>> hex_to_rgb('fff')    # white
(255, 255, 255)
my_code_base.plot.colors.rgb_to_dec(value: list[float]) tuple[float][source]

Convert rgb to decimal colours (i.e. divides each value by 255)

Parameters:
value : list (length 3) of RGB values

Returns:

list (length 3) of decimal values

Return type:

tuple[float]

Example

>>> rgb_to_dec((255, 0, 0))
(1.0, 0.0, 0.0)