visualastro.Colorsets#

class Colorsets[source]#

Bases: object

Query and plot registered VisualAstro colorsets.

property available#

Canonical names of the registered VisualAstro colorsets.

Aliases and Matplotlib built-in colorsets (e.g. 'tab10') 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.

query

Filter and sort colorset names.

property aliases#

Mapping of colorset 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]#

Get a colorset by name or alias.

Thin wrapper around get_colorset(). See that function for the full description of the options.

Parameters:
  • name (str) – Colorset name or alias.

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

  • transform ({'lighten', 'darken', 'saturate', 'desaturate'} | None, optional) – Color transform to apply. Default is set by get_colorset.

  • factor (float, optional) – Transform strength. Default is set by get_colorset.

  • cvd_type ({'deuteranomaly', 'protanomaly', 'tritanomaly'} | None, optional, default=None) – Color vision deficiency to simulate.

  • severity (int, optional, default=100) – Severity of the simulated deficiency.

Returns:

Colors in the requested format.

Return type:

list

See also

visualastro.get_colorset

Underlying implementation.

query(*, length=None, min_length=None, max_length=None, sort_by=None, reverse=False)[source]#

Filter and sort colorset names.

Parameters:
  • length (int | None, optional, default=None) – Absolute length of colors.

  • min_length (int | None, optional, default=None) – Minimum number of colors (inclusive).

  • max_length (int | None, optional, default=None) – Maximum number of colors (inclusive).

  • sort_by ({'name', 'length'} | None, optional, default=None) – Sort criterion. If None, registration order is kept.

  • reverse (bool, optional, default=False) – Reverse the sort order.

Returns:

names – Matching canonical colorset names.

Return type:

list[str]

Raises:

ValueError – If sort_by is not a valid criterion.

plot(colorset=None, *, show_color_name=True, length=None, min_length=None, max_length=None, sort_by=None, reverse=False, transform=_Unset.UNSET, factor=_Unset.UNSET, cvd_type=None, severity=100, width=8, savefig=False)[source]#

Plot the colorset(s), optionally with additional filters.

Any of the filters in query() are valid arguments if colorset is None.

Parameters:
  • colorset (str | None, optional, default=None) – Colorset name or alias, or a color or sequence of colors. If None, plots all colorsets unless one or more of the filters are used.

  • show_color_name (bool, optional, default=True) – If True, also plots the colorset name. Only applicable to VisualAstro colorsets (as opposed to a sequence of colors).

  • length (int | None, optional, default=None) – Absolute length of colors.

  • min_length (int | None, optional, default=None) – Minimum number of colors (inclusive).

  • max_length (int | None, optional, default=None) – Maximum number of colors (inclusive).

  • sort_by ({'name', 'length'} | None, optional, default=None) – Sort criterion. If None, registration order is kept.

  • reverse (bool, optional, default=False) – Reverse the sort order.

  • transform ({'lighten', 'darken', 'saturate', 'desaturate'} | None | _Unset, optional, default=_UNSET) – Method to modify the colors. If None, colors are unchanged. If _UNSET, uses config.color_transform.

  • factor (float | _Unset, optional, default=_UNSET) – Modification strength, see get_colors. If _UNSET, uses config.color_transform_factor.

  • cvd_type ({'deuteranomaly', 'protanomaly', 'tritanomaly', 'all'} | None, optional, default=None) – Type of colorblindness to simulate. Can be shorthanded to 'd', 'p', 't'. If 'all', simulates all cvd types. If None, no colorblindness simulation is applied.

  • severity (float, optional, default=100) – Severity of colorblindness. Must be < 100.

  • width (float | int | None, optional, default=8) – Width of the colorset plot.

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

Return type:

None

preview(colorset, *, cmap=_Unset.UNSET, linestyle='solid', linewidth=2, transform=_Unset.UNSET, legend=True, loc='bottom center', ncols=4, factor=_Unset.UNSET, cvd_type=None, severity=100)[source]#

Plot a sample figure demonstrating a VisualAstro color set.

Parameters:
  • colors (ColorType | int | Sequence[ColorType | int], optional, default='astro_seq') – Color set to visualize. Can be either a VisualAstro colorset name, a color, an integer, or a sequence of colors. If an int, generates a sequence of colors by sampling cmap.

  • ax (matplotlib.axes.Axes | None, optional, default=None) – The Axes object on which to plot the demo orbits. If None, uses plt.gca().

  • cmap (Colormap | _Unset, optional, default=_UNSET) – Colormap used to generate a sequence of colors if colors is an int. If _UNSET uses config.colors.

  • linestyle (LineStyleType, optional, default='solid') – Line style of each line.

  • linewidth (float, optional, default=2) – Line width of each line.

  • legend (bool, optional, default=True) – If True, plots the legend.

  • loc (str, optional, default='bottom center') – Legend location.

  • ncols (int, optional, default=4) – Number of columns in the legend.

  • transform ({'lighten', 'darken', 'saturate', 'desaturate'} | None | _Unset, optional, default=_UNSET) – Method to modify the colors. If None, colors are unchanged. If _UNSET, uses config.color_transform.

  • factor (float | _Unset, optional, default=_UNSET) – Modification strength, see get_colors. If _UNSET, uses config.color_transform_factor.

  • cvd_type ({'deuteranomaly', 'protanomaly', 'tritanomaly', 'all'} | None, optional, default=None) – Type of colorblindness to simulate. Can be shorthanded to 'd', 'p', 't'. If 'all', simulates all cvd types. If None, no colorblindness simulation is applied.

  • severity (float, optional, default=100) – Severity of colorblindness. Must be < 100.

Returns:

Artists returned by the plotting functions, grouped by plot element.

Return type:

list[list[Line2D | PatchCollection]]