Colour-vision-deficiency checks

Simulate how colours, palettes and whole figures look to readers with a colour-vision deficiency, and in greyscale print. The simulations use the Machado, Oliveira & Fernandes (2009) model and need no extra packages. See Colours for the guide.

plotastro.simulate_cvd(colors, kind='deuteranopia')[source]

Simulate how colours appear with a colour-vision deficiency.

Parameters:
  • colors (colour, sequence of colours, or (..., 3/4) float array) – Anything matplotlib understands (hex strings, names, RGB tuples, an image array from a rendered figure, …).

  • kind ({"deuteranopia", "protanopia", "tritanopia", "greyscale"}) – Deficiency to simulate. Deuteranopia and protanopia (red-green) together affect ~5% of male readers; greyscale is what a black-and-white printout shows.

Returns:

  • ndarray of RGB(A) values in [0, 1], one row per input colour (or the

  • same shape as an input image array).

Notes

Uses the severity-1.0 matrices of Machado et al. (2009), applied in linear RGB — the same model behind most online CVD simulators.

plotastro.check_colors(palette=None, kinds=('deuteranopia', 'protanopia', 'greyscale'))[source]

Show a palette next to CVD simulations of it, to verify that the colours stay distinguishable.

Parameters:
  • palette (dict, list of colours, or None) – Defaults to the package’s colour cycle.

  • kinds (sequence of str) – Simulations to include (see simulate_cvd()).

Returns:

Figure

Return type:

one row of swatches per simulation, under the original.

Examples

>>> pa.check_colors()                       # the default cycle
>>> pa.check_colors(pa.cmasher_colors("torch", n=6))
plotastro.check_figure(fig=None, kinds=('deuteranopia', 'protanopia', 'greyscale'))[source]

Render an existing figure and show how it appears under CVD simulations — the final accessibility check before submission.

Parameters:
  • fig (Figure, optional) – Defaults to the current figure.

  • kinds (sequence of str) – Simulations to include (see simulate_cvd()).

Return type:

The new comparison figure.