---
title: "ColorFunction"
language: "en"
type: "Symbol"
summary: "ColorFunction is an option for graphics functions that specifies a function to apply to determine colors of elements."
keywords: 
- color lookup table
- color map
- color palette
- color spectrum
- colormap
- color gradient
- texture
- surface texture
- curve texture
- color field
- color space
- color model
- IDLgrPalette
- LOADCT
- STRETCH
- caxis
- colorbar
- colormap
- colormapeditor
- contrast
- cool
- copper
- flag
- hot
- hsv
- lines
- prism
- shading
- spinmap
- spring
- summer
- winter
canonical_url: "https://reference.wolfram.com/language/ref/ColorFunction.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Colors"
    link: "https://reference.wolfram.com/language/guide/Colors.en.md"
  - 
    title: "Plotting Options"
    link: "https://reference.wolfram.com/language/guide/PlottingOptions.en.md"
  - 
    title: "Vector Visualization"
    link: "https://reference.wolfram.com/language/guide/VectorVisualization.en.md"
  - 
    title: "Graphics Options & Styling"
    link: "https://reference.wolfram.com/language/guide/GraphicsOptionsAndStyling.en.md"
  - 
    title: "Financial Visualization"
    link: "https://reference.wolfram.com/language/guide/FinancialVisualization.en.md"
  - 
    title: "Chart Styling & Layout"
    link: "https://reference.wolfram.com/language/guide/ChartLayoutAndStyling.en.md"
related_functions: 
  - 
    title: "ColorFunctionScaling"
    link: "https://reference.wolfram.com/language/ref/ColorFunctionScaling.en.md"
  - 
    title: "MeshShading"
    link: "https://reference.wolfram.com/language/ref/MeshShading.en.md"
  - 
    title: "PlotStyle"
    link: "https://reference.wolfram.com/language/ref/PlotStyle.en.md"
  - 
    title: "NormalsFunction"
    link: "https://reference.wolfram.com/language/ref/NormalsFunction.en.md"
  - 
    title: "Blend"
    link: "https://reference.wolfram.com/language/ref/Blend.en.md"
  - 
    title: "ColorData"
    link: "https://reference.wolfram.com/language/ref/ColorData.en.md"
  - 
    title: "LightDarkAutoColorRules"
    link: "https://reference.wolfram.com/language/ref/LightDarkAutoColorRules.en.md"
related_tutorials: 
  - 
    title: "Density and Contour Plots"
    link: "https://reference.wolfram.com/language/tutorial/TheStructureOfGraphicsAndSound.en.md#14270"
---
# ColorFunction

ColorFunction is an option for graphics functions that specifies a function to apply to determine colors of elements.

## Details

* With ``ColorFunction -> func``, the arguments supplied to ``func`` are as follows:

|                                                        |                             |
| ------------------------------------------------------ | --------------------------- |
| Raster                                                 | a                           |
| Plot, ListLinePlot, ListLogPlot                        | x, y                        |
| ParametricPlot                                         | x, y, u or x, y, u, v       |
| RegionPlot                                             | x, y                        |
| ArrayPlot, ReliefPlot                                  | a                           |
| ContourPlot, ListContourPlot                           | f contour levels            |
| DensityPlot, ListDensityPlot                           | f                           |
| ContourPlot3D, ListContourPlot3D                       | x, y, z, f                  |
| Plot3D, ListPlot3D, ListSurfacePlot3D, ListPointPlot3D | x, y, z                     |
| ParametricPlot3D                                       | x, y, z, u or x, y, z, u, v |
| RegionPlot3D                                           | x, y, z                     |
| Image3D, Raster3D                                      | a                           |

* With the usual default setting ``ColorFunctionScaling -> True``, all arguments supplied to ``func`` are scaled to lie in the range 0 to 1.

* With ``ColorFunctionScaling -> False``, original unscaled values are used.

* ``ColorFunction -> "name"`` is equivalent to ``ColorFunction -> (ColorData["name"][#i]&)`` where the slot used is as follows: ``Plot``, ``ListPlot``, etc.: ``#2`` ($y$); ``ArrayPlot``, ``ReliefPlot``: ``#1`` ($a$); ``ContourPlot``, ``DensityPlot``, etc.: ``#1`` ($f$); ``ContourPlot3D``, etc.: ``#4`` ($f$); ``Plot3D``, etc.: ``#3`` ($z$).

* The list of possible color function names is given by ``ColorData["Gradients"]``.

* The function specified by ``ColorFunction`` must return color directives such as ``RGBColor`` and ``Hue`` or named colors such as ``Red`` and ``Blue``.

* It can also return ``Opacity``, as well as ``Glow`` and ``Specularity``.

* Combinations of directives can be specified using ``Directive[g1, g2, …]``.

* In 3D graphics, ``ColorFunction`` by default specifies diffuse colors for surfaces.

* If an explicit setting is given for ``ColorRules``, ``MeshShading``, or ``ContourShading``, it is used in preference to the setting for ``ColorFunction``.

---

## Examples (8)

### Basic Examples (5)

Color the surface by height:

```wl
In[1]:= Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> Function[{x, y, z}, Hue[z]]]

Out[1]= [image]
```

---

Use predefined gradients:

```wl
In[1]:= Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "BlueGreenYellow"]

Out[1]= [image]

In[2]:= DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "BlueGreenYellow"]

Out[2]= [image]
```

---

Color a curve:

```wl
In[1]:= Plot[Sinc[x], {x, 0, 10}, PlotStyle -> Thick, ColorFunction -> Function[{x, y}, ColorData["NeonColors"][y]]]

Out[1]= [image]
```

---

Color a matrix:

```wl
In[1]:= ArrayPlot[RandomReal[1, {10, 20}], ColorFunction -> "Rainbow"]

Out[1]= [image]
```

---

Color a 3D volume:

```wl
In[1]:= Image3D[ExampleData[{"TestImage3D", "CTengine"}], ColorFunction -> "RainbowOpacity"]

Out[1]= [image]
```

### Applications (1)

Define a one-dimensional color function:

```wl
In[1]:= CoolColor[ z_ ]  := RGBColor[z, 1 - z, 1];

In[2]:= ContourPlot[Sin[x y], {x, -1, 1}, {y, -1, 1}, ColorFunction -> CoolColor]

Out[2]= [image]

In[3]:= DensityPlot[Sin[x y], {x, -1, 1}, {y, -1, 1}, ColorFunction -> CoolColor]

Out[3]= [image]
```

### Properties & Relations (1)

Use predefined color gradients from ``ColorData`` :

```wl
In[1]:= GraphicsGrid[Partition[Tooltip[ColorData[#, "Image"], #]& /@ ColorData["Gradients"], 3], ImageSize -> 300]

Out[1]= [image]
```

### Possible Issues (1)

By default, the arguments to ``ColorFunction`` are rescaled to be between 0 and 1:

```wl
In[1]:= Plot3D[x * y, {x, -6, 6}, {y, -6, 6}, ColorFunction -> Function[{x, y, z}, If[TrueQ[x * y > 0], Blue, Green]]]

Out[1]= [image]
```

Turn off ``ColorFunctionScaling`` to keep the original values:

```wl
In[2]:= Plot3D[x * y, {x, -6, 6}, {y, -6, 6}, ColorFunction -> Function[{x, y, z}, If[TrueQ[x * y > 0], Blue, Green]], ColorFunctionScaling -> False]

Out[2]= [image]
```

## See Also

* [`ColorFunctionScaling`](https://reference.wolfram.com/language/ref/ColorFunctionScaling.en.md)
* [`MeshShading`](https://reference.wolfram.com/language/ref/MeshShading.en.md)
* [`PlotStyle`](https://reference.wolfram.com/language/ref/PlotStyle.en.md)
* [`NormalsFunction`](https://reference.wolfram.com/language/ref/NormalsFunction.en.md)
* [`Blend`](https://reference.wolfram.com/language/ref/Blend.en.md)
* [`ColorData`](https://reference.wolfram.com/language/ref/ColorData.en.md)
* [`LightDarkAutoColorRules`](https://reference.wolfram.com/language/ref/LightDarkAutoColorRules.en.md)

## Tech Notes

* [Density and Contour Plots](https://reference.wolfram.com/language/tutorial/TheStructureOfGraphicsAndSound.en.md#14270)

## Related Guides

* [`Colors`](https://reference.wolfram.com/language/guide/Colors.en.md)
* [Plotting Options](https://reference.wolfram.com/language/guide/PlottingOptions.en.md)
* [Vector Visualization](https://reference.wolfram.com/language/guide/VectorVisualization.en.md)
* [Graphics Options & Styling](https://reference.wolfram.com/language/guide/GraphicsOptionsAndStyling.en.md)
* [Financial Visualization](https://reference.wolfram.com/language/guide/FinancialVisualization.en.md)
* [Chart Styling & Layout](https://reference.wolfram.com/language/guide/ChartLayoutAndStyling.en.md)

## Related Links

* [An Elementary Introduction to the Wolfram Language: Pure Anonymous Functions](https://www.wolfram.com/language/elementary-introduction/26-pure-anonymous-functions.html)

## History

* Introduced in 1991 (2.0) \| Updated in 1999 (4.0) ▪ 2000 (4.1) ▪ 2002 (4.2) ▪ [2007 (6.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn60.en.md) ▪ [2012 (9.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn90.en.md)