hclplotfunction of the
colorspacepackage. Depending on the palette type the "color pane" goes along different dimensions. Please note that this feature is in its beta state and still under development.
'set lon -20 40'
'set lat 30 85'
'set mpdset hires'
'set mproj nps'
'set mpvals -10 30 34 52'
'set gxout shaded'
'set lev 850'
'set gxout contour'
'set string 3 l'
'draw string 1 1 NCEP GFS 1 deg analysis: relative humidity 850hPa'
from numpy.random import uniform, seed
from matplotlib.mlab import griddata
import matplotlib.pyplot as plt
import numpy as np
npts = 200
x = uniform(-2,2,npts)
y = uniform(-2,2,npts)
z = x*np.exp(-x**2-y**2)
xi = np.linspace(-2.1,2.1,100)
yi = np.linspace(-2.1,2.1,200)
zi = griddata(x,y,z,xi,yi,interp='linear')
CS = plt.contour(xi,yi,zi,len(colors)-1,linewidths=0.5,colors='k')
CS = plt.contourf(xi,yi,zi,len(colors)-1,colors=colors,
plt.colorbar() # draw colorbar
plt.title('griddata test (%d points)' % npts)
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
hclwizard()on your local machine. Both graphical user interfaces return an R color palette function. However, you can also use the function call below to use the current palette in your R scripts.
register = "Custom-Palette"is set (where
"Custom-Palette"is the name of your new palette) the palette will be added to the list of available color palettes. Existing palettes can also be overruled. Note that the graphical interfaces (
choose_palette()) will not use custom palettes. These register-calls can also be added to your local
Jason C. Fisher, Reto Stauffer, Achim Zeileis
A graphical user interface (GUI) for viewing, manipulating, and choosing HCL color palettes.
Computes palettes based on the HCL (hue-chroma-luminance) color model (as
polarLUV). The GUIs interface the palette
qualitative_hcl for qualitative palettes,
sequential_hcl for sequential palettes with a single or
multiple hues, and
diverging_hcl for diverging palettes (composed
from two single-hue sequential palettes).
Two different GUIs are implemented and can be selected using the function
"shiny"). Both GUIs
allows for interactive modification of the arguments of the respective
palette-generating functions, i.e., starting/ending hue (wavelength, type of
color), minimal/maximal chroma (colorfulness), minimal maximal luminance
(brightness, amount of gray), and a power transformations that control how
quickly/slowly chroma and/or luminance are changed through the palette.
Subsets of the parameters may not be applicable depending on the type of
palette chosen. See
qualitative_hcl and Zeileis et al. (2009) for
a more detailed explanation of the different arguments. Stauffer et al.
(2015) provide more examples and guidance.
Optionally, active palette can be illustrated by using a range of examples such as a map, heatmap, scatter plot, perspective 3D surface etc.
To demonstrate different types of deficiencies, the active palette may be
desaturated (emulating printing on a grayscale printer) and collapsed to
emulate different types of color-blindness (without red-green or green-blue
contrasts) using the
choose_palette by default starts the Tcl/Tk version of the GUI while
hclwizard by default starts the shiny version.
an alias for
Returns a palette-generating function with the selected arguments. Thus, the returned function takes an integer argument and returns the corresponding number of HCL colors by traversing HCL space through interpolation of the specified hue/chroma/luminance/power values.
Qualitative, sequential (single-hue and multi-hue), and diverging color palettes based on the HCL (hue-chroma-luminance) color model.
The HCL (hue-chroma-luminance) color model is a perceptual color model
obtained by using polar coordinates in CIE
polarLUV), where steps of equal size correspond to
approximately equal perceptual changes in color. By taking polar coordinates
the resulting three dimensions capture the three perceptual axes very well:
hue is the type of color, chroma the colorfulness compared
to the corresponding gray, and luminance the brightness. This makes it relatively
easy to create balanced palettes through trajectories in this HCL space.
In contrast, in the more commonly-used
model (a simple transformation of
RGB), the three axes are
confounded so that luminance changes along with the hue leading to very
unbalanced palettes (see
rainbow_hcl for further illustrations).
Three types of palettes are derived based on the HCL model:
Qualitative: Designed for coding categorical information, i.e., where no particular ordering of categories is available and every color should receive the same perceptual weight.
Sequential: Designed for coding ordered/numeric information, i.e., where colors go from high to low (or vice versa).
Diverging: Designed for coding numeric information around a central neutral value, i.e., where colors diverge from neutral to two extremes.
The corresponding functions are
diverging_hcl. Their construction principles are explained in more detail below.
At the core is the luminance axis (i.e., light-dark contrasts):
These are easily decoded by humans and matched to high-low differences in the underlying
sequential_hcl palettes are always based on a monotonic
luminance sequence whereas the colors in a
qualitative_hcl palette all have the
same luminance. Finally,
diverging_hcl palettes use the same monotonic
luminance sequence in both “arms” of the palette, i.e., correspond to
two balanced sequential palettes diverging from the same neutral value.
The other two axes, hue and chroma, are used to enhance the luminance information and/or
to further discriminate the color.
All three palette functions specify trajectories in HCL space and hence need either
single values or intervals of the coordinates
interfaces are always designed such that
l can take vector
arguments (as needed) but alternatively or additionally
l2 can be specified. If so,
the latter coordinates overwrite the former.
qualitative_hcl distinguishes the underlying categories by a sequence of
hues while keeping both chroma and luminance constant to give each color in the
resulting palette the same perceptual weight. Thus,
h should be a pair of
hues (or equivalently
h2 can be used) with the starting and
ending hue of the palette. Then, an equidistant sequence between these hues is
employed, by default spanning the full color wheel (i.e, the full 360 degrees).
c (or equivalently
c1) and luminance
l (or equivalently
l1) are constants.
sequential_hcl codes the underlying numeric values by a monotonic sequence
of increasing (or decreasing) luminance. Thus, the
l argument should provide
a vector of length 2 with starting and ending luminance (equivalently,
l2 can be used). Without chroma (i.e.,
c = 0), this simply corresponds
to a grayscale palette like
gray.colors. For adding chroma, a simple
strategy would be to pick a single hue (via
h1) and then decrease
chroma from some value (
c1) to zero (i.e., gray) along with
increasing luminance. For bringing out the extremes (a dark high-chroma color vs.
a light gray) this is already very effective. For distinguishing also colors in the
middle two strategies can be employed: (a) Hue can be varied as well by specifying an
interval of hues in
h (or beginning hue
h1 and ending hue
(b) Instead of a decreasing chroma a triangular chroma trajectory can be employed
c2 (or equivalently a vector
length 3). This yields high-chroma colors in the middle of the palette that are
more easily distinguished from the dark and light extremes. Finally, instead of
employing linear trajectories, power transformations are supported in chroma and
luminance via a vector
power (or separate
p2) for the luminance trajectory is missing, it defaults
p1 from the chroma trajectory.
diverging_hcl codes the underlying numeric values by a triangular luminance
sequence with different hues in the left and in the right arm of the palette. Thus,
it can be seen as a combination of two sequential palettes with some restrictions:
(a) a single hue is used for each arm of the palette, (b) chroma and luminance trajectory
are balanced between the two arms, (c) the neutral central value has zero chroma.
To specify such a palette a vector of two hues
h (or equivalently
h2), either a single chroma value
c1) or a vector
of two chroma values
cmax), a vector of two
l2), and power parameter(s)
p2) are used. For more flexible diverging palettes without
the restrictrictions above (and consequently more parameters)
divergingx_hcl is available. For backward compatibility,
is a copy of
To facilitate using HCL-based palettes a wide range of example palettes are
provided in the package and can be specified by a name instead of a set of
parameters/coordinates. The examples have been taken from the literature and many
approximate color palettes from other software packages such as ColorBrewer.org
(RColorBrewer), CARTO colors (rcartocolor), or scico. The function
hcl_palettes can be used to query the available pre-specified palettes. It
comes with a
(additionally listing the underlying parameters/coordinates), and a
method that creates a
swatchplot with suitable labels.
Visualization of color palettes (given as hex codes) in HCL and/or RGB coordinates.
specplot transforms a given color palette in hex codes
into their HCL (
polarLUV) and/or RGB
sRGB) 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.
By default (
plot = TRUE), the resulting HCL and optionally RGB coordinates are
visualized by simple line plots along with the color palette
For comparing two palettes,
specplot(x, y) can be used which adds
lines (dashed, by default) corresponding to the
y palette HCL/RGB
coordinates in the display.
specplot invisibly returns a list with components
a matrix of HCL coordinates,
a matrix of sRGB coordinates,
original color palette
Visualization of color palettes in HCL space projections.
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.
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 (e.g., as in the highly
saturated base R palettes).
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
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.
hclplot invisibly returns a matrix with the HCL coordinates corresponding to
Zeileis A, Hornik K, Murrell P (2009). Escaping RGBland: Selecting Colors for Statistical Graphics. Computational Statistics & Data Analysis, 53, 3259–3270. doi: 10.1016/j.csda.2008.11.033 Preprint available from https://eeecon.uibk.ac.at/~zeileis/papers/Zeileis+Hornik+Murrell-2009.pdf.
Stauffer R, Mayr GJ, Dabernig M, Zeileis A (2015). Somewhere over the Rainbow: How to Make Effective Use of Colors in Meteorological Visualizations. Bulletin of the American Meteorological Society, 96(2), 203–216. doi: 10.1175/BAMS-D-13-00155.1