from colorspace import rainbow_hcl, diverging_hcl
from colorspace import specplot
= rainbow_hcl()
pal 21)); specplot(pal.colors(
Color Spectrum Plot
Description
Visualization of color palettes (given as hex codes) in HCL and/or RGB coordinates.
As the hues for low-chroma colors are not (or poorly) identified, by default a smoothing is applied to the hues (fix = TRUE
). Also, to avoid jumps from 0
to 360
or vice versa, the hue coordinates are shifted suitably.
If argument x
is a maplotlib.colors.LinearSegmentedColormap
or matplotlib.colors.ListedColormap
, 256
distinct colors across the color map are drawn and visualized.
Usage
specplot(x, y=None, hcl=True, palette=True,
fix=True, rgb=False, title=None, fig=None,
**figargs)
Arguments
-
x
list, LinearSegmentedColormap, ListedColormap
-
list of str (hex colors or standard-names of colors) or a
matplotlib.colors.LinearSegmentedColormap
. -
y
None, list, LinearSegmentedColormap
-
if set it must be a list of str (see
x
) with the very same length as the object provided on argumentx
or amaplotlib.colors.LinearSegmentedColormap
. Allows to draw two sets of colors for comparison, defaults toNone
. -
hcl
bool
- Whether or not to plot the HCL color spectrum.
-
palette
bool
- Whether or not to plot the colors as a color map (color swatch).
-
fix
bool
- Should the hues be fixed to be on a smooth(er) curve? Details in the functions description.
-
rgb
bool
-
Whether or not to plot the RGB color spectrum, defaults to
False
. -
title
None or str
-
title of the figure. Defaults to
None
(no title). -
fig
None, matplotlib.figure.Figure
-
If
None
, a newmatplotlib.figure.Figure
is created. -
**figargs
-
forwarded to
matplotlib.pyplot.subplot
. Only has an effect iffig = None
.
Examples
# Show spectrum in standard RGB space
21), rgb = True); specplot(pal.colors(
# Reduced number of colors.
# Show sRGB spectrum, hide HCL spectrum
# and color palette swatch.
= True, hcl = False,
specplot(pal.colors(), rgb = False, figsize = (8, 3)); palette
# Comparing full diverging_hcl() color spectrum to
# a LinearSegmentedColormap (cmap) with only 5 colors
# (an extreme example)
"Green-Orange").colors(101),
specplot(diverging_hcl("Green-Orange").cmap(5),
diverging_hcl(= True, figsize = (8, 3)); rgb
# Same as above using .cmap() default with N = 256 colors
"Green-Orange").colors(101),
specplot(diverging_hcl("Green-Orange").cmap(),
diverging_hcl(= True, figsize = (8, 3)); rgb
Raises
-
ImportError
: Ifmatplotlib
is not installed. -
TypeError
: Ifx
is not list ormatplotlib.colors.LinearSegmentedColormap
. -
TypeError
: Ify
is neither a list norNone
. -
ValueError
: Ifx
contains str which can not be converted to hex colors. -
ValueError
: Ify
contains str which can not be converted to hex colors. -
ValueError
: Ify
is not the same length asy
. Only checked ify
is notNone
. -
TypeError
: If eitherrgb
,hcl
, orpalette
is not bool. -
ValueError
: If all,rgb
,hcl
andpalette
are set toFalse
as this would result in an empty plot. -
TypeError
: If 'title' is neitherNone
norstr
.