File Exchange

image thumbnail

CubeHelix Colormap Generator: Beautiful and Versatile!

version (16.7 KB) by Stephen Cobeldick
The most versatile colormap generator ever! Generate colormaps suitable for grayscale conversion.


Updated 13 Aug 2018

GitHub view license on GitHub

This is the only colormap generator you need: CubeHelix are the best colormaps for published or distributed documents!

CUBEHELIX allows you to create different colormaps using just a few parameters. The standard CubeHelix algorithm offer very attractive colorschemes for online and electronic documents (e.g. PDF), and yet when printed in grayscale they keep exactly the sequence information of the original data. CUBEHELIX also includes two extra controls over the range and domain of the CubeHelix scheme, giving a practically unlimited number of colormaps with many different styles: maximally distinct, multi or single hue, or even simple grayscale.

### Bonus Functions ###

* CUBEHELIX_FIND can be used to retrieve the parameters from an existing CubeHelix colormap, or to find the best CubeHelix colorscheme that matches any selection of colors (e.g. a document or corporate colorscheme).
* CUBEHELIX_VIEW creates a figure for creating CubeHelix colorschemes with real-time interactive adjustment of the scheme's parameter values, plus a 'random' demonstration mode. It also allows adjustment of other axes' or figures' colormaps, for example:
load spine

### CubeHelix ###

CubeHelix colorschemes consist of nodes along a tapered helix in the RGB color cube, with a continuous increase in perceived intensity (e.g. black->white). Thus the scheme defines attractive colormaps with a huge choice of hue, saturation and brightness, and yet printing a figure (or image) in Black-and-White (e.g. postscript) results in a monotonically increasing grayscale that retains the brightness order of the original colormap. The sequence information of the colormap is retained even in grayscale, which means an attractive colored image can be printed in grayscale and still be informative to the end-user.

The scheme is defined here:
For more information and examples:

Note: The original specification (the links above) misnamed the saturation option as "hue". In this submission the saturation option is named "sat".

### Examples ###

% New colors for the COLORMAP example:
load spine

% New colors for the SURF example:
[X,Y,Z] = peaks(30);

### Examples of Viewing CubeHelix Colormaps ###

% Interactive colorscheme parameter viewer:
% Set/reset the viewer with new parameter values:

### Examples of Retrieving CubeHelix Colormap Parameters ###

ans = [0.5,-1.5,1,1]

map = cubehelix(10, 1.4,-0.7,0.9,1.2, [0.05,0.97]);
[vec,irg,dmn] = cubehelix_find(map)
vec = [1.4,-0.7,0.9,1.2]
irg = [0.05,0.97]
dmn = [0,1]

map = cubehelix(64, [2.3,0.4,0.5,0.6], [0.05,0.24], [0.19,0.85]);
[vec,irg,dmn] = cubehelix_find(map)
vec = [2.3,0.4,0.5,0.6]
irg = [0.05,0.24]
dmn = [0.19,0.85]

Cite As

Stephen Cobeldick (2020). CubeHelix Colormap Generator: Beautiful and Versatile! (, GitHub. Retrieved .

Comments and Ratings (9)


Martin Ward

E. Cheynet

@rockthekasbah: You would need to generate two colormaps, and concatenate them vertically, something like this:

map1 = cubehelix(10,2,2,1,1);
map2 = cubehelix(10,1,0,1,1);
map = [map1;map2(end:-1:1,:)];

I spent quite some time investigating this concept myself, with the intention of writing a wrapper function that returns a diverging colormap constructed from two cubehelix maps. However the huge number of input parameters (up to eight values for each cubehelix map) made it a users nightmare. Determining the color of the midpoint is not a simple task: should it be automatically determined? If so, how? What happens if the user defines two maps with very different colors at the join: what would the mid-point color be? Should the function force the user to make the adjacent colors match?

In the end I decided that because concatenating two colormaps is trivially easy, it was not worth the complexity of its own function.

How do I create a diverging colormap out of this? I played around with different settings but it is taking forever to find one. Is there an easier way?



Excellent function. Works well, creates nice colours that do not trick the reader and prints well in gray scales. It does what it is supposed to do.




* Simplfiy CUBEHELIX_VIEW figure creation.

* Update FEX blurb.

* Replace that awful automatically-generated title with the original title.

* Move to GitHub repository.
Changes to "cubehelix_view":
* Simplify internal graphics-handle management.
* Simplify figure layout.

* Minor edit to blurb, consistent parameter names.

* Use correct color terminology: rename "hue" -> "sat", and "start" -> "hue".

* Change input name from <rng> to <yrange> to avoid conflict with inbuilt function.
* Simplify input checking.
* Simplify internal passing of variables to local functions.

* Include Domain option.
* Include 3D RGB-cube viewer.
* More robust parameter finder.

- Improve input argument checking.

- Improve input argument checking.
- Viewer figure now displays warnings for clipped RGB or non-monotonic grayscale values.
- Demo now also varies the range values.

- Allow parameters to be input as a vector.
- Improve viewer background.
- Better demonstration-mode: random examples in the viewer.

- Add range sliders to viewer.
- Slightly robuster finder algorithm.
- Show some nice examples in the illustration!

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