Wolfram Research

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/2 beginning hue
"Rotations" -3/2 cycles of all hues
"Hue" 1 colorfulness of median values
"Gamma" 1 emphasis on higher/lower values
"MinLight" 0 lightness for minimum values
"MaxLight" 1 lightness for maximum values
"MinHue" 0 colorfulness 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 do we cycle through all hues. 0 means that we only use one hue, 1 means that we cycle through all hues once, -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, 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 over-saturated.
“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

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

Scope

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

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]=

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

Options

“Start”

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

“Rotations”

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”

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”

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

Rainbow

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[2]=

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

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

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

Neat Examples

Animated pastels

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

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]=

Resource History

Source Metadata

License Information