How can I easily control the color shading of ArrayPlot? Say I want to go from white to dark green in a gradient form.

• how about ListDensityPlot[matrix, ColorFunction -> (Blend[{Green, White}, #] &), ScalingFunctions -> {None, "Reverse"}]? (using matrix from your other question)
– kglr
Nov 29, 2020 at 1:44
• Yes, worked! Thanksssss Nov 29, 2020 at 2:01

Use Blend and ColorFunction to make a gradient of colors for ArrayPlot. Here's an example that uses a gradient of colors from white to dark green.

SeedRandom[123]
data = RandomReal[9, {10, 20}];
ArrayPlot[data,
ColorFunction -> Function[{a}, Blend[{White, Darker@Green}, a]]]


Blend[{color1, color2}, x] works by mixing a fraction (1 - x) of the first color with a fraction x of the second color, where x is between 0 and 1. A table of 12 colors from white to green shows how Blend works.

Table[Blend[{White, Darker@Green}, x], {x, Subdivide[0, 1, 11]}]


matrix = {{5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{5, 5, 5, 5, 5, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{5, 5, 5, 5, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{5, 5, 5, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{5, 5, 3, 3, 3, 2, 1, 1, 1, 1, 1,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