from colorspace import swatchplot, palette
from colorspace import sequential_hcl, diverging_hcl, heat_hcl
# List of hex colors
'#7FBFF5', '#2A4962', '#111111', '#633C39', '#F8A29E'],
swatchplot([= (7, 0.5)); figsize
Palette Swatch Plot
Description
Visualization of color palettes in columns of color swatches. The first argument pals
is very flexible and can be:
- List of hex colors,
- a single object which inherits from
colorspace.palettes.palette
,colorspace.palettes.hclpalette
,colorspace.colorlib.colorobject
, - a list of objects listed above (all of the same type or mixed),
- a dictionary with lists of objects as above. If a dictionary is used the keys of the dictionary are used as ‘subtitles’ to group sets of palettes,
- an object of class
colorspace.palettes.hclpalettes
, - or an object of class
matplotlib.colors.LinearSegmentedColormap
ormatplotlib.colors.ListedColormap
.
Requires the matplotlib
to be installed.
Usage
swatchplot(pals, show_names=True, nrow=20, n=5,
cvd=None, **kwargs)
Arguments
-
pals
- The color palettes or color objects to be visualized. See description for details and examples to demonstrate different usages.
-
show_names
bool
- Should palette names be shown (if available), defaults to True.
-
nrow
int
-
Maximum number of rows of swatches, defaults to
20
. -
n
int
-
Number of colors to be drawn from palette objects, defaults to
5
. -
cvd
None or list
-
Allows to display one or multiple palettes and how they look with emulated color vision deficiencies. If
None
, this is not applied. Can be set to a list of characters. Allowed:"protan"
,"tritan"
,"deutan"
,"desaturate"
corresponding to the functions protan, tritan, deutan, desaturate. -
**kwargs
-
forwarded to
matplotlib.pyplot.subplot
, can be used to control e.g.,figsize
.
Examples
# Create a custom 'palette' (named):
= palette(['#7FBFF5', '#2A4962', '#111111', '#633C39', '#F8A29E'],
pal "Custom Named Palette")
= (7, 0.5)); swatchplot(pal, figsize
# A HCL palette. 'n' defines the number of colors.
"PuBu"), n = 10,
swatchplot(sequential_hcl(= (7, 0.5)); figsize
# Combine all three
'#7FBFF5', '#2A4962', '#111111', '#633C39', '#F8A29E'],
swatchplot([["PuBu")], n = 7,
pal, sequential_hcl(= (7, 1.5)); figsize
# A color object (e.g., RGB, HCL, CIELUV, ...)
from colorspace.colorlib import hexcols
= hexcols(heat_hcl()(5))
cobject "HCL")
cobject.to(print(cobject)
polarLUV color object (5 colors)
H C L
1: 359.96 100.56 50.04
22.73 95.68 60.00
44.77 91.06 69.91
67.39 82.91 79.91
90.40 29.80 90.06
= (7, 0.5)); swatchplot(cobject, figsize
# Using dictionaries to add subtitles
# to 'group' different palettes.
"Diverging": [diverging_hcl(), diverging_hcl("Red-Green")],
swatchplot({"Sequential": [sequential_hcl("ag_Sunset"), sequential_hcl("OrRd")],
"Others": [['#7FBFF5', '#2A4962', '#111111', '#633C39', '#F8A29E'],
"PuBu")]}, n = 15); pal, sequential_hcl(
Raises
-
ImportError
: Ifmatplotlib
is not installed. -
TypeError
: Ifnrow
orn
no int. -
TypeError
: Ifshow_names
not bool. -
ValueError
: Ifnrow
orn
are not positive. -
ImportError
: Ifmatplotlib.pyplot
cannot be imported, maybematplotlib
not installed?