Function Repository Resource:

CubehelixColorFunction

Source Notebook

Generate color functions using the "cubehelix" method

Contributed by: Cody Woodard (Wolfram Research)

ResourceFunction["CubehelixColorFunction"][options]

generate a "cubehelix" color function based on given options.

Details and Options

The following options can be given:
"Start"1/2beginning hue
"Rotations"-3/2cycles of all hues
"Hue"1colorfulness of median values
"Gamma"1emphasis on higher/lower values
"MinLight"0lightness for minimum values
"MaxLight"1lightness for maximum values
"MinHue"0colorfulness of extreme values
"Start" defines the starting hue of the color function, where 1 = red, 2 = green and 3 = blue. The default value (1/2) is purple.
"Rotations" defines how many times we cycle through all hues. 0 means that we only use one hue, 1 means that we cycle through all hues once and -2 means that we cycle through all hues twice but in a reverse direction. The default value (-3/2) means that we cycle through all hues one and a half times in a reverse direction.
"Hue" (which is really chroma) defines how colorful the function is. 0 means that there is no color and 1 (the default value) means that there is a default amount of color. You can use values greater than 2.6, but they will tend to be oversaturated.
"Gamma" shifts the lightness curve and should be a value greater than 0 but less than 2. The default value (1) provides a linear curve. Lower values (like 1/4) will lighten all colors but will leave low values dark. Higher values (like 3/4) will darken all colors but will leave high values light.
"MinLight" defines the lightness value for minimum values. The default value is 0, meaning that the minimum value will be black.
"MaxLight" defines the lightness value for maximum values. The default value is 1, meaning that the maximum value will be white.
"MinHue" defines how colorful the extreme values of the function will be. The default value is 0, meaning that the function will be most colorful in the middle and the minimum/maximum values will have no color.

Examples

Basic Examples (1) 

Store and use the ColorFunction returned using default values:

In[1]:=
basicCubeHelix = ResourceFunction["CubehelixColorFunction"][];
In[2]:=
DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> basicCubeHelix]
Out[2]=

Scope (3) 

Default ColorFunction used for a Plot3D:

In[3]:=
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> Function[{x, y, z}, basicCubeHelix[z]]]
Out[3]=

Default ColorFunction used for an ArrayPlot:

In[4]:=
ArrayPlot[
 Table[Evaluate[Sum[Sin[RandomReal[10, 2] . {x, y}], {5}]], {x, 0, 5, .1}, {y, 0, 5, .1}], ColorFunction -> basicCubeHelix]
Out[4]=

Default ColorFunction used for a ReliefPlot:

In[5]:=
data = Import["http://exampledata.wolfram.com/hailey.dem.gz", "Data"];
ReliefPlot[data, ColorFunction -> basicCubeHelix, PlotLegends -> Automatic]
Out[5]=

Options (4) 

Start (1) 

"Start" defines the starting hue of the color function, where 1 = red, 2 = green and 3 = blue:

In[6]:=
Multicolumn[(# -> DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> ResourceFunction["CubehelixColorFunction"]["Start" -> #]] & /@ Range[0, 3, 1/2])]
Out[6]=

Rotations (1) 

"Rotations" defines how many times we cycle through all hues. 0 means that we only use one hue, 1 means that we cycle through all hues once and -2 means that we cycle through all hues twice but in a reverse direction:

In[7]:=
Multicolumn[(# -> DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> ResourceFunction["CubehelixColorFunction"][
        "Rotations" -> #]] & /@ {-3, -2, -1, -1/2, 0, 1/2, 1, 2, 3})]
Out[7]=

Hue (1) 

"Hue" (which is really chroma) defines how colorful the function is. 0 means that there is no color and 1 means that there is a default amount of color. You can use values greater than 2.6, but they will tend to be oversaturated:

In[8]:=
Multicolumn[(# -> DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> ResourceFunction["CubehelixColorFunction"][
        "Hue" -> #]] & /@ {0, 1/2, 1, 3/2, 2})]
Out[8]=

Gamma (1) 

"Gamma" shifts the lightness curve and should be a value greater than 0 but less than 2. The default value (1) provides a linear curve. Lower values (like 1/4) will lighten all colors but will leave low values dark. Higher values (like 3/4) will darken all colors but will leave high values light:

In[9]:=
Multicolumn[(# -> DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> ResourceFunction["CubehelixColorFunction"][
        "Gamma" -> #]] & /@ {1/4, 1/2, 1, 3/2, 2})]
Out[9]=

Applications (3) 

Rainbow (2) 

You can use these options to create a rainbow gradient:

In[10]:=
rainbowColorFunction = ResourceFunction["CubehelixColorFunction"]["Start" -> 3/4, "Rotations" -> 1, "MinLight" -> 3/4, "MaxLight" -> 3/4, "MinHue" -> 2, "Hue" -> 2];
DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> rainbowColorFunction]
Out[10]=

This is the same as if we used LCHColor directly:

In[11]:=
DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> Function[{x}, LCHColor[3/4, 1, x]]]
Out[11]=

Custom Color Functions (1) 

Here are a couple of presets you might like:

In[12]:=
coolColorFunction = ResourceFunction["CubehelixColorFunction"]["Start" -> 1, "Rotations" -> -1, "Hue" -> 1/2];
DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> coolColorFunction]
Out[12]=
In[13]:=
thermogramColorFunction = ResourceFunction["CubehelixColorFunction"]["Start" -> 0, "Rotations" -> 1/2, "Hue" -> 4/3];
DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> thermogramColorFunction]
Out[13]=

Neat Examples (2) 

Animated Pastels (1) 

This creates an animated gradient:

In[14]:=
Animate[DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> ResourceFunction["CubehelixColorFunction"]["Start" -> start, "Rotations" -> 2/5, "MinLight" -> 1/2, "Hue" -> 1/2, "MinHue" -> 1/2]], {start, 0, 3}]
Out[14]=

Cubehelix Explorer (1) 

You can use this manipulate to play around with the options:

In[15]:=
Manipulate[
 DensityPlot[x, {x, 0, 1}, {y, 0, 1}, ColorFunction -> ResourceFunction["CubehelixColorFunction"]["Start" -> start, "Rotations" -> rotations, "Hue" -> hue, "Gamma" -> gamma, "MinLight" -> minlight, "MaxLight" -> maxlight, "MinHue" -> minhue], ColorFunctionScaling -> True], {{start, .5}, 0, 3}, {{rotations, -1.5}, -5, 5}, {{minhue, 0}, 0, 2}, {{hue, 1}, 0, 2}, {{gamma, 1}, 0, 2}, {{minlight, 0}, 0, 1}, {{maxlight, 1}, 0,
   1}]
Out[15]=

Version History

  • 1.0.0 – 15 July 2019

Source Metadata

Author Notes

Note: This is not a faithful port of the original FORTRAN code, but a complete novel reimplementation. I have tried to match the results as closely as possible to other implementations, but it will not be exact.

License Information