Skip to content

colorutils

colorutils

Module for all color functions and variables

Classes

Color

Bases: tuple, Enum

Enum for RGB color tuples used for visualization

Functions

get_color

get_color(idx)

returns a color tuple with len 3 for a color between 0 and 1

Source code in niceml/utilities/colorutils.py
def get_color(idx: int) -> Tuple[float, float, float]:
    """returns a color tuple with len 3 for a color between 0 and 1"""
    return COLORS[idx % len(COLORS)]

get_color_array

get_color_array(classes_array)

Returns an array with colors for each class

Parameters:

  • classes_array (List) –

    List of classes to generate colors for

Returns:

  • ndarray

    Array of one color per class

Source code in niceml/utilities/colorutils.py
def get_color_array(classes_array: List) -> np.ndarray:
    """
    Returns an array with colors for each class

    Args:
        classes_array: List of classes to generate colors for

    Returns:
        Array of one color per class
    """
    color_list = [get_color(color) for color in classes_array]
    return np.array(color_list)

get_color_array_uint

get_color_array_uint()

returns a color array with shape (len(COLORS),3) with values between 0 and 255

Source code in niceml/utilities/colorutils.py
def get_color_array_uint() -> np.ndarray:
    """returns a color array with shape (len(COLORS),3) with values between
    0 and 255"""
    color_list = [get_color(idx) for idx in range(len(COLORS))]
    color_array = np.array(color_list)
    color_array = (color_array * 255).astype(np.uint8)
    return color_array

get_color_uint

get_color_uint(idx)

returns a color tuple with len 3 for a color between 0 and 255

Source code in niceml/utilities/colorutils.py
def get_color_uint(idx: int) -> Tuple[int, int, int]:
    """returns a color tuple with len 3 for a color between 0 and 255"""
    color = [int(x * 255) for x in get_color(idx)]
    return tuple(color)