8
$\begingroup$

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 -> (* ??? *)]
$\endgroup$
10
$\begingroup$
ArrayPlot[RandomReal[1, {10, 10}], 
 ColorFunction -> (Blend[{Green, Red}, #] &)]

enter image description here

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}}, #] &)]

enter image description here

$\endgroup$
  • $\begingroup$ this is exactly what I've been looking for. thx $\endgroup$ – RMMA Aug 7 '12 at 7:17
  • $\begingroup$ @rainer glad to help $\endgroup$ – VLC Aug 7 '12 at 7:22
  • $\begingroup$ 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}, #] &. $\endgroup$ – J. M. will be back soon Aug 7 '12 at 7:24
  • $\begingroup$ @J.M. you're right, I just wanted to show how the blending can be adapted for special cases. $\endgroup$ – VLC Aug 7 '12 at 7:26
8
$\begingroup$

This works:

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

red-green array plot


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}, #].

$\endgroup$
4
$\begingroup$

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"]

enter image description here

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)] &)]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.