bluemira.display.palettes

Colour palettes

Attributes

BLUEMIRA_PALETTE

LONDON_PALETTE

BLUE_PALETTE

Classes

ColorPalette

Color palette object, wrapping some seaborn functionality.

Functions

background_colour_string(→ str)

make_rgb_alpha() → tuple[float, Ellipsis])

Adds a transparency to a RGB color tuple

make_alpha_palette(→ ColorPalette)

Make a palette from a color by varying alpha.

colour_string(→ str)

Colour a string with ANSI codes

Module Contents

class bluemira.display.palettes.ColorPalette(palette_map: dict[str, matplotlib.typing.ColorType])

Color palette object, wrapping some seaborn functionality.

Parameters:

palette_map (dict[str, matplotlib.typing.ColorType]) – Dictionary of color names to any object matplotlib will recognise as a color

_dict
_palette = []
_cycle
keys()
Returns:

Keys of ColorPalette

__next__()
Returns:

the next color in the ColorPalette

__setitem__(idx_or_key: int | str, value: matplotlib.typing.ColorType | ColorPalette)

Set an item in the ColorPalette by index or key

Parameters:
  • idx_or_key (int | str) – Index or key of the ColorPalette

  • value (matplotlib.typing.ColorType | ColorPalette) – The value to set. Note that this can be another ColorPalette

__getitem__(idx_or_key: int | str) matplotlib.typing.ColorType | ColorPalette | None

Get an item in the ColorPalette by index or key

Parameters:

idx_or_key (int | str) – Index or key of the ColorPalette

Returns:

The value. Note that this can be another ColorPalette

Return type:

value

_hex_horizontal() list[str] | list[list[str]]
Returns:

A list of strings representing a horizontal row of hex colors, or a list of lists of strings where each inner list represents a row of hex colors.

Return type:

list[str] | list[list[str]]

_repr_html() str
Return type:

str

_repr_colour_str(_hex: list[str] | list[list[str]]) str
Returns:

colourful representation in terminal

Parameters:

_hex (list[str] | list[list[str]])

Return type:

str

__repr__() str
Returns:

a representation of the ColorPalette

Return type:

str

__len__() int
Returns:

the length of the ColorPalette

Return type:

int

as_hex() list[str] | list[list[str]] | str
Returns:

the hex representation of the palette

Return type:

list[str] | list[list[str]] | str

bluemira.display.palettes.background_colour_string(hexstring: str, sqlen=2) str
Returns:

ANSI background colour string for hex colour

Parameters:

hexstring (str)

Return type:

str

bluemira.display.palettes.make_rgb_alpha(rgb: tuple[float, Ellipsis], alpha: float, background_rgb: tuple[float, Ellipsis] = (1.0, 1.0, 1.0)) tuple[float, Ellipsis]

Adds a transparency to a RGB color tuple

Parameters:
  • rgb (tuple[float, Ellipsis]) – Tuple of 3 RGB floats (0<=float<=1)

  • alpha (float) – Transparency as a fraction (0<=float<=1)

  • background_rgb (tuple[float, Ellipsis]) – 3 RGB floats (0<=float<=1), background colour (default = white)

Return type:

The RGB tuple accounting for transparency

bluemira.display.palettes.make_alpha_palette(color, n_colors: int, background_rgb: matplotlib.typing.ColorType = 'white') ColorPalette

Make a palette from a color by varying alpha.

Parameters:
  • color (Any) – Palette base color. Anything matplotlib will recognise as a color

  • n_colors (int) – Numer of colors to make in the palette

  • background_rgb (matplotlib.typing.ColorType) – Background color. Anything matplotlib will recognise as a color

Returns:

Colour palette from the base color. The first color is the base color

Return type:

ColorPalette

bluemira.display.palettes.colour_string(string: str, colour: str) str

Colour a string with ANSI codes

Parameters:
  • string (str) – The text to colour

  • colour (str) – The colour to make the colour-string for

Returns:

The string with ANSI colour decoration

Return type:

str

bluemira.display.palettes.BLUEMIRA_PALETTE
bluemira.display.palettes.LONDON_PALETTE
bluemira.display.palettes.BLUE_PALETTE