ColorRules
是一个选项,用以指定单元的颜色如何由值来确定.
更多信息
- 由 ColorRules 给定的规则应用于各单元的值.
- ColorRules 的规则可包括模式.
- 如果应用 ColorRules 的结果为 None,则将使用背景色.
- 若 ColorRules 中无规则可用,则使用 ColorFunction 来确定颜色.
- 若缺省设置 ColorRules->Automatic,则用明确的 ColorFunction->f 设置来替代 ColorRules.
范例
打开所有单元 关闭所有单元基本范例 (4)
对 ArrayPlot 使用颜色规则:
ArrayPlot[{{a, 1}, {2, b}}, ColorRules -> {a -> Yellow, b -> Blue}]对 MatrixPlot 使用颜色规则:
MatrixPlot[{{1, 0, 3}, {0, 2, 0}, {0, 0, 4}}, ColorRules -> {0 -> Yellow, _ -> Blue}]对 GeoRegionValuePlot 使用颜色规则:
GeoRegionValuePlot[{Entity["Country", "Netherlands"] -> 2, Entity["Country", "Greece"] -> 3, Entity["Country", "Spain"] -> 4}, ColorRules -> {2 -> Orange, 3 -> Blue, 4 -> Red}]对 Colorize 使用颜色规则:
Colorize[MorphologicalComponents[[image]], ColorFunction -> "Rainbow", ColorRules -> {0 -> White}]范围 (4)
ColorRules 可包含模式:
ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {1 -> Red, 2 -> Yellow, _ -> White}]如果没有明确的颜色规则,则使用缺省 ArrayPlot 色彩:
ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {1 -> Red}]ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {1 -> Red}, ColorFunction -> "IslandColors"]设置为 None 的情况用背景色渲染:
ArrayPlot[{{1, 2, 3}, {4, 2, 1}, {2, 1, 3}}, ColorRules -> {3 | 4 -> None}, Background -> Blue]应用 (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}}]ArrayPlot[Table[GCD[i, j], {i, 20}, {j, 20}], ColorRules -> {1 -> Red}]ArrayPlot[CellularAutomaton[{1635, {3, 1}}, {{1}, 0}, 50], ColorRules -> {0 -> Black, 1 -> Red, 2 -> Yellow}]历史
2004年引入 (5.1)
文本
Wolfram Research (2004),ColorRules,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ColorRules.html.
CMS
Wolfram 语言. 2004. "ColorRules." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/ColorRules.html.
APA
Wolfram 语言. (2004). ColorRules. Wolfram 语言与系统参考资料中心. 追溯自 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: 10-September-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: 10-September-2026]}