visualastro.Colors#

class Colors[source]#

Bases: _ColorRegistry[tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]]

Query and plot registered VisualAstro named colors.

See color guide for usage documentation.

property available#

Canonical names of the registered VisualAstro named colors.

Aliases and Matplotlib named colors are excluded. Use aliases to list alias names.

Returns:

Colorset names present in both COLORSETS and the Matplotlib color sequence registry, in registration order.

Return type:

list of str

See also

aliases

Mapping of alias names to canonical names.

property aliases#

Mapping of named color aliases to canonical names.

Only aliases registered in the Matplotlib color sequence registry are included.

Returns:

Keys are alias names, values are the canonical names in available they resolve to.

Return type:

dict of str to str

See also

available

Canonical colorset names.

get(name, *, fmt='hex', transform=_Unset.UNSET, factor=_Unset.UNSET, cvd_type=None, severity=100)[source]#

Retrieve a single color to the requested format, optionally applying a color transform and a color vision deficiency (CVD) simulation.

Parameters:
  • color (str) – A single color name.

  • fmt ({'hex', 'rgb', 'rgba'}, optional, default='hex') – Output color format.

  • transform ({'lighten', 'darken', 'saturate', 'desaturate'} | None | _Unset, optional, default=_UNSET) –

    Transform applied to the color.

    • None: no transform.

    • _UNSET: use config.color_transform.

  • factor (float | _Unset, optional, default=_UNSET) – Transform strength, see get_colors. Ignored if transform is None. If _UNSET, use config.color_transform_factor.

  • cvd_type ({'deuteranomaly', 'protanomaly', 'tritanomaly'} | None, optional, default=None) –

    CVD type to simulate, applied after transform. Shorthands 'd', 'p', 't' are accepted.

    • 'all': simulate every CVD type.

    • None: no simulation.

  • severity (int, optional, default=100) – CVD severity in [0, 100], where 100 is complete color blindness. Ignored if cvd_type is None.

Returns:

str for fmt='hex', RGBTuple for fmt='rgb', RGBATuple for fmt='rgba'.

Return type:

str | RGBTuple | RGBATuple

plot(family=None, *, ncols=4, sort_colors=True, transform=None, factor=0.5, cvd_type=None, severity=100)[source]#

Plot a grid of colors with their names.

This function is adapted from a Matplotlib gallery example: https://matplotlib.org/stable/gallery/color/named_colors.html

Copyright (c) 2012-2023 Matplotlib Development Team. Licensed under the Matplotlib License (BSD-compatible) https://matplotlib.org/stable/users/project/license.html

Parameters:
  • colors (dict[str, ColorType] | str | None, optional, default=None) –

    Dictionary containing colors to plot, or one of the following:

    • 'named_colors' or None: VisualAstro and Matplotlib named colors

    • 'mpl' or 'matplotlib' or 'mpl_colors' or 'matplotlib_colors' or 'css4': Matplotlib named colors

    • 'xkcd' or 'xkcd_colors': XKCD named colors

    • 'visualastro' or 'va': VisualAstro named colors

    • 'base' or 'base_colors': Matplotlib base colors

    • 'tableau' or 'tableau_colors': Matplotlib tableau colors

    • 'all' or 'all_colors': All of the above

  • ncols (int, optional, default=4) – Number of columns to plot.

  • sort_colors (bool, optional, default=True) – If True, sort colors by hsv value.

  • transform ({'lighten', 'darken', 'saturate', 'desaturate'} | None, optional, default=None) – Transform applied to every color before sorting and CVD simulation. If None, colors are unchanged.

  • factor (int | float, optional, default=0.5) – Transform strength. Ignored if transform is None.

  • cvd_type ({'deuteranomaly', 'protanomaly', 'tritanomaly'} | None, optional, default=None) – CVD type to simulate, applied after transform. If None, no simulation is applied.

  • severity (int, optional, default=100) – CVD severity in [0, 100], where 100 is complete color blindness. Ignored if cvd_type is None.

  • savefig – If True, save the figure to disk with savefig. Opens a prompt to set the file name and extention.