# Adapt ColorFunction in Array Plot

The problem I'm facing is how to adapt ColorFunction so that it ranges from green (low values) to red (high values):

ArrayPlot[{a1, a2, a3, a4, a5}, ColorFunction -> (* ??? *)]

-

ArrayPlot[RandomReal[1, {10, 10}],
ColorFunction -> (Blend[{Green, Red}, #] &)]


If you need to specify a more specific range of colors:

ArrayPlot[RandomReal[1, {10, 10}],
ColorFunction -> (Blend[{{0, Darker[Green]}, {.25, Green}, {.5,
Yellow}, {.75, Orange}, {1, Red}}, #] &)]


-
this is exactly what I've been looking for. thx – RMMA Aug 7 '12 at 7:17
@rainer glad to help – VLC Aug 7 '12 at 7:22
If the points are equispaced, as in Blend[{{0, Darker[Green]}, {.25, Green}, {.5, Yellow}, {.75, Orange}, {1, Red}}, #] &, one can just give the list of colors to Blend[]: Blend[{Darker[Green], Green, Yellow, Orange, Red}, #] &. – J. M. Aug 7 '12 at 7:24
@J.M. you're right, I just wanted to show how the blending can be adapted for special cases. – VLC Aug 7 '12 at 7:26

This works:

ArrayPlot[Array[BitXor, {64, 64}, {0, 0}], ColorFunction -> (RGBColor[#, 1 - #, 0] &)]


Here's a little utility function for automatically generating a color function that linearly interpolates between two colors:

linearColorFunction[colMin_?ColorQ, colMax_?ColorQ] :=
Function[Evaluate[RGBColor @@ Chop[Expand[{1 - #, #}.
(List @@@ ColorConvert[{colMin, colMax}, RGBColor])]]]]


Examples:

linearColorFunction[Green, Red] (* OP's example *)
RGBColor[1. #1, 1. - 1. #1, 0] &

linearColorFunction[Cyan, Magenta] (* "cool" colormap in MATLAB *)
RGBColor[1. #1, 1. - 1. #1, 1.] &


As already noted, the function generated by linearColorFunction[colMin, colMax] behaves the same way as the function Blend[{colMin, colMax}, #].

-

Here are some data:

data = Table[x + Sin[3 x + y^2], {x, -3, 3, .01}, {y, -3, 3, .01}];


In Mathematica there are designated so called Color Schemes. For example in your case you could use "RoseColors":

ArrayPlot[data, ColorFunction -> "RoseColors"]


But I personally would go with "TemperatureMap" as good indicator of low/high values. Another way to is to use Hue with modified argument to get green-red for start-end of the scale:

ArrayPlot[{Range[0, 1, .01]}, AspectRatio -> 1/4, ColorFunction -> (Hue[.8 (# + .3)] &)]


-