is an option that specifies how colors of cells should be determined from values.
ColorRules
is an option that specifies how colors of cells should be determined from values.
Details
- The rules given by ColorRules are applied to the value of each cell.
- Rules for ColorRules can involve patterns.
- If the result from applying ColorRules is None, the background color will be used.
- If none of the rules in ColorRules apply, then ColorFunction is used to determine the color.
- With the default setting ColorRules->Automatic, an explicit setting ColorFunction->f is used instead of ColorRules.
Examples
open all close allBasic Examples (4)
Use color rules for ArrayPlot:
ArrayPlot[{{a, 1}, {2, b}}, ColorRules -> {a -> Yellow, b -> Blue}]Use color rules for MatrixPlot:
MatrixPlot[{{1, 0, 3}, {0, 2, 0}, {0, 0, 4}}, ColorRules -> {0 -> Yellow, _ -> Blue}]Use color rules for GeoRegionValuePlot:
GeoRegionValuePlot[{Entity["Country", "Netherlands"] -> 2, Entity["Country", "Greece"] -> 3, Entity["Country", "Spain"] -> 4}, ColorRules -> {2 -> Orange, 3 -> Blue, 4 -> Red}]Use color rules for Colorize:
Colorize[MorphologicalComponents[[image]], ColorFunction -> "Rainbow", ColorRules -> {0 -> White}]Scope (4)
ColorRules can involve patterns:
ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {1 -> Red, 2 -> Yellow, _ -> White}]If no explicit color rules apply, the default ArrayPlot coloring is used:
ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {1 -> Red}]Color rules are applied before color function:
ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {1 -> Red}, ColorFunction -> "IslandColors"]Cases specified as None are rendered in the background color:
ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {3 | 4 -> None}, Background -> Blue]Applications (3)
Table[ArrayPlot[Table[Mod[f[i, j], 5], {i, 0, 40}, {j, 0, 40}], ColorRules -> {0 -> White, 1 -> Yellow, 2 -> Orange, 3 -> Pink, 4 -> Red}], {f, {Plus, Subtract, Times}}]Highlight cells where the GCD is 1:
ArrayPlot[Table[GCD[i, j], {i, 20}, {j, 20}], ColorRules -> {1 -> Red}]Color a cellular automaton pattern:
ArrayPlot[CellularAutomaton[{1635, {3, 1}}, {{1}, 0}, 50], ColorRules -> {0 -> Black, 1 -> Red, 2 -> Yellow}]Related Guides
History
Introduced in 2004 (5.1)
Text
Wolfram Research (2004), ColorRules, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorRules.html.
CMS
Wolfram Language. 2004. "ColorRules." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ColorRules.html.
APA
Wolfram Language. (2004). ColorRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ColorRules.html
BibTeX
@misc{reference.wolfram_2026_colorrules, author="Wolfram Research", title="{ColorRules}", year="2004", howpublished="\url{https://reference.wolfram.com/language/ref/ColorRules.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_colorrules, organization={Wolfram Research}, title={ColorRules}, year={2004}, url={https://reference.wolfram.com/language/ref/ColorRules.html}, note=[Accessed: 12-June-2026]}