# Sequential HCL palette, hclplot with all available options
from colorspace import sequential_hcl, hclplot
= sequential_hcl("PurpOr")(5)
x
hclplot(x,= "Chroma dimension",
xlabel = "Luminance dimension",
ylabel = "hclplot Example (Sequential)",
title = (5, 5), s = 250); figsize
Palette Plot in HCL Space
Description
The function hclplot
is an auxiliary function for illustrating the trajectories of color palettes in two-dimensional HCL space projections. It collapses over one of the three coordinates (either the hue H or the luminance L) and displays a heatmap of colors combining the remaining two dimensions. The coordinates for the given color palette are highlighted to bring out its trajectory.
The function hclplot
has been designed to work well with the hcl_palettes in this package. While it is possible to apply it to other color palettes as well, the results might look weird or confusing if these palettes are constructed very differently.
More specifically, the following palettes can be visualized well:
Qualitative with (approximately) constant luminance. In this case,
hclplot
shows a hue-chroma plane (in polar coordinates), keeping luminance at a fixed level (by default displayed in the main title of the plot). If the luminance is, in fact, not approximately constant, the luminance varies along with hue and chroma, using a simple linear function (fitted by least squares).hclplot
shows a chroma-luminance plane, keeping hue at a fixed level (by default displayed in the main title of the plot). If the hue is, in fact, not approximately constant, the hue varies along with chroma and luminance, using a simple linear function (fitted by least squares.Diverging with two (approximately) constant hues: This case is visualized with two back-to-back sequential displays.
To infer the type of display to use, by default, the following heuristic is used: If luminance is not approximately constant (range > 10
) and follows rougly a triangular pattern, a diverging display is used. If luminance is not constant and follows roughly a linear pattern, a sequential display is used. Otherwise a qualitative display is used.
Note: Requires matplotlib
to be installed.
Usage
hclplot(x, _type=None, h=None, c=None, l=None,
axes=True, linewidth=1, s=150, **kwargs)
Arguments
-
x
str, list, colorobject
- An object which can be converted into a hexcols object.
-
_type
None, str
-
Specifying which type of palette should be visualized (
"qualitative"
,"sequential"
, or"diverging"
). For qualitative palettes a hue-chroma plane is used, otherwise a chroma-luminance plane. By default (_type = None
) the type is inferred from the luminance trajectory corresponding tox
. -
h
None, int, float
-
If int or float, it must be within
[-360, 360]
-
c
None, int, float
- If int or float, it must be positive
-
l
None, int, float
- If int or float, it must be positive
-
axes
bool
-
Wheter or not axes should be drawn, defaults to
True
. -
linewidth
int, float, None
-
Line width, if set
0
orNone
the line connecting the colors of the palette will be suppressed. -
s
int, float, None
-
Marker size, defaults to
150
. If set0
orNone
the position of the colors of the palette will be suppressed. -
**kwargs
-
Allowed to overwrite some default settings such as
title
(str),xlabel
(str),ylabel
(str),figsize
(forwarded topyplot.figure
).xlabel
/ylabel
only used for qualitative and diverging plots. A matplotlib axis can be provided viaax
(object of typematplotlib.axes._axes.Axes
) which allows to draw multiple HCL spaces on one figure.
Return
No return, visualizes the palette and HCL space either on a new figure or on an existing axis (if ax
is provided, see **kwargs
).
Examples
# Multiple subplots
import matplotlib.pyplot as plt
from colorspace import sequential_hcl, hclplot
# Three different palettes
= sequential_hcl(h = 260, c = 80, l = [35, 95], power = 1)
pal1 = sequential_hcl(h = 245, c = [40, 75, 0], l = [30, 95], power = 1)
pal2 = sequential_hcl(h = 245, c = [40, 75, 0], l = [30, 95], power = [0.8, 1.4]) pal3
pal1.show_settings()
Class: sequential_hcl
h1 260.0
h2 260.0
c1 80.0
cmax ---
c2 0
l1 35.0
l2 95.0
p1 1.0
p2 1.0
fixup True
pal2.show_settings()
Class: sequential_hcl
h1 245.0
h2 245.0
c1 40.0
cmax 75.0
c2 0.0
l1 30.0
l2 95.0
p1 1.0
p2 1.0
fixup True
pal3.show_settings()
Class: sequential_hcl
h1 245.0
h2 245.0
c1 40.0
cmax 75.0
c2 0.0
l1 30.0
l2 95.0
p1 0.8
p2 1.4
fixup True
= plt.subplots(1, 3, figsize = (12, 4))
fig, (ax1, ax2, ax3) 7), ax = ax1)
hclplot(pal1(7), ax = ax2)
hclplot(pal2(7), ax = ax3)
hclplot(pal3(; plt.show()
# Another example with two sequential and one
# diverging palettes with custom settings
from colorspace import sequential_hcl, diverging_hcl, hclplot
import matplotlib.pyplot as plt
= sequential_hcl(h = [260, 220], c = [50, 0, 75], l = [30, 95], power = 1)
pal1 = sequential_hcl(h = [260, 60], c = 60, l = [40, 95], power = 1)
pal2 = diverging_hcl( h = [260, 0], c = 80, l = [35, 95], power = 1)
pal3
= plt.subplots(1, 3, figsize = (12, 4))
fig, (ax1, ax2, ax3) 7), ax = ax1)
hclplot(pal1(7), ax = ax2)
hclplot(pal2(7), ax = ax3)
hclplot(pal3(; plt.show()
# Another example with two sequential and one
# diverging palettes with custom settings
from colorspace import sequential_hcl, diverging_hcl, qualitative_hcl, hclplot
import matplotlib.pyplot as plt
= plt.subplots(1, 3, figsize = (12, 4))
fig, (ax1, ax2, ax3) 7), ax = ax1)
hclplot(sequential_hcl()(7), ax = ax2)
hclplot(diverging_hcl()(7), ax = ax3)
hclplot(qualitative_hcl()(; plt.show()
Raises
-
ImportError
: Ifmatplotlib
is not installed. -
TypeError
: If argument_type
is not None or str. -
TypeError
: If argument_type
is str but not one of the allowed types. -
TypeError
: If argumentc
, and/orl
are not None, str, or int. -
TypeError
: If argumenth
is neither None, int, float, or tuple, or tuple not containing int/float. -
ValueError
: Ifc
,l
is not None and smaller or equal to0
(must be positive). -
ValueError
: Ifh
is tuple length0
or>2
(must be one or two). -
ValueError
: Ifh
is not None and not within the range[-360, 360]
. -
TypeError
: Ifs
,linewidth
are not int, float, or None. -
ValueError
: Ifs
,linewidth
are int/float but negative (<0
).