Impose the color for one discrete value above a color predefined gradient
Adding the option
ColorRules -> {0 -> White}
to ArrayPlot works.
Sorry I find the answer 1 min after I ask the question...
Not all plot functions accept ColorRules
, so it is good to know how to construct a custom color function anyway. For this example:
cf = If[# == 0, White, "Rainbow" ~Blend~ #] &;
ArrayPlot[a, ColorFunction -> cf]
More specified colors can be applied with Piecewise
. Custom color functions can also apply to multiple dimensions:
cf = Piecewise[{
{Green, 0.2 < #2 < 0.3},
{Cyan, 0.7 < #2 < 0.8},
{Yellow, 0.2 < #1 < 0.3},
{Black, 0.7 < #1 < 0.8}
}, Blend["Rainbow", #]] &;
Plot[TriangleWave[x], {x, 0, 5},
PlotStyle -> AbsoluteThickness[5], ColorFunction -> cf, PlotPoints -> 5000]
You should also see MeshFunctions
, MeshStyle
, etc. for such things, which would not require such an extreme PlotPoints
value, but I wished to make a point.
One could also use Lighter[]
for the purpose:
ArrayPlot[a, ColorFunction -> (Lighter[ColorData["Rainbow", #], Boole[# == 0]] &)]