File Exchange

image thumbnail


version 1.3 (431 KB) by Aslak Grinsted
Generate pleasing HSL colormaps easily.

1 Download

Updated 04 Feb 2015

View License

Generate hue-saturation-lightness colormaps

USAGE: hslcolormap(N,H,S,L)

N: number of colors in colormap.
H: hue stops (optional). %can also be specified using a string: rygcbmRYGCBM
S: saturation stops (optional)
L: Lightness stops (optional)

The stops are placed evenly over the colorscale. Parameter examples:
H=[0 1/6]; %colorscale runs from red to yellow
S=[0 1]; %gray to fully saturated
L=[.3 1 .3]; % dark-bright-dark

Using L with two-stops (e.g. L=[.2 .8]) makes it easy to distinguish
high and low values.

Using a symmetric L with 3 stops (e.g. L=[.2 1 .2]) is useful for divergent

Discontinuities in the colormap can be indicated with nans.

caxis([-6 6])
hslcolormap(300,'g.m',1,[.1 1 .1]);

(c) Aslak Grinsted 2014

Cite As

Aslak Grinsted (2019). hslcolormap (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

the dot inserts a discontinuity in the hue at that point.

Ray Lee

Can you explain the effect of dot in the hue codes?



can now take hue inputs as string. e.g. y=yellow=1/6

added discontinuity feature, and added html example

added screenshot

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux