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
aliasesto list alias names.- Returns:
Colorset names present in both
COLORSETSand the Matplotlib color sequence registry, in registration order.- Return type:
See also
aliasesMapping 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
availablethey resolve to.- Return type:
dict of str to str
See also
availableCanonical 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: useconfig.color_transform.
factor (float | _Unset, optional, default=_UNSET) – Transform strength, see
get_colors. Ignored iftransformisNone. If_UNSET, useconfig.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_typeisNone.
- Returns:
strforfmt='hex',RGBTupleforfmt='rgb',RGBATupleforfmt='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'orNone: 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
transformisNone.cvd_type ({'deuteranomaly', 'protanomaly', 'tritanomaly'} | None, optional, default=None) – CVD type to simulate, applied after
transform. IfNone, no simulation is applied.severity (int, optional, default=100) – CVD severity in [0, 100], where 100 is complete color blindness. Ignored if
cvd_typeisNone.savefig – If
True, save the figure to disk withsavefig. Opens a prompt to set the file name and extention.