Infamous sRGB Rainbow Color Palette

Description

Implements the (in-)famous rainbow (or jet) color palette that was used very frequently in many software packages but has been widely criticized for its many perceptual problems. It is specified by a start and end hue \(\in [0.-1.]\) with red = 0, yellow = 1/6, green = 2/6, cyan = 3/6, blue = 4/6, and magenta = 5/6. However, these are very flashy and unbalanced with respect to both chroma and luminance which can lead to various optical illusions. Also, the hues that are equispaced in RGB space tend to cluster at the red, green, and blue primaries. Therefore, it is recommended to use a suitable palette from hcl.colors instead of rainbow.

start and/or end both allow for lambda functions with one single argument n (number of colors), see examples.

See also: qualitative_hcl, sequential_hcl, diverging_hcl, divergingx_hcl, rainbow_hcl, heat_hcl, terrain_hcl, and diverging_hsv.

Usage

rainbow(s=1, v=1, start=0,
end=<function rainbow.<lambda>>,
rev=False, *args, **kwargs)

Arguments

sfloat, int
saturation value, a value in [0., 1.]. Defaults to 1.0.
vfloat, int
value, a value in [0., 1.]. Defaults to 1.0.
startfloat, int, function
the (corrected) hue in [0., 1.] at which the rainbow begins. Defaults to 0.. Can be a function with one input n (number of colors). If outside [0., 1.] it will be wrapped.
endfloat, int, function
the (corrected) hue in [0., 1.] at which the rainbow ends. Defaults to 0.. Can be a function with one input n (number of colors). If outside [0., 1.] it will be wrapped.
revbool
Should the color map be reversed.
*args
Unused.
**kwargs
Unused.

Return

Initialize new object, no return. Raises a set of errors if the parameters are misspecified. Note that the object is callable, the default object call can be used to return hex colors (identical to the .colors() method), see examples.

Methods

rainbow.cmap(n=256, name='custom_hcl_cmap')
Create Matplotlib Compatible Color Map
rainbow.colors(n=11, alpha=None, **kwargs)
Get Colors
rainbow.get(key)
Get Specific Palette Setting
rainbow.hclplot(n=7, **kwargs)
Palette Plot in HCL Space
rainbow.name()
Get Palette Name
rainbow.show_settings()
Show Palette Settings
rainbow.specplot(n=180, *args, **kwargs)
Color Spectrum Plot
rainbow.swatchplot(n=7, **kwargs)
Palette Swatch Plot

Examples

from colorspace import rainbow
pal = rainbow()
pal.colors(10)
['#FF0000',
 '#FF9900',
 '#CCFF00',
 '#33FF00',
 '#00FF66',
 '#00FFFF',
 '#0066FF',
 '#3300FF',
 '#CC00FF',
 '#FF0099']
pal.swatchplot(show_names = False, figsize = (5.5, 0.5));

# The standard call of the object also returns hex colors
rainbow()(10)
['#FF0000',
 '#FF9900',
 '#CCFF00',
 '#33FF00',
 '#00FF66',
 '#00FFFF',
 '#0066FF',
 '#3300FF',
 '#CC00FF',
 '#FF0099']
# Using lambda functions for start/end
p = rainbow(start = lambda n: 1 / n, end = lambda n: 1 - 1 / n)
p.swatchplot(n = 5, show_names = False, figsize = (5.5, 0.5));

p.swatchplot(n = 10, show_names = False, figsize = (5.5, 0.5));

p.specplot(rgb = True, figsize = (8, 6))

Raises

  • TypeError: If s or v are not float or int.
  • ValueError: If s or v are outside range, must be in [0., 1.].
  • TypeError: If start and end are not float/int in [0., 1.] or lambda functions.
  • TypeError: If rev is not bool.