Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 -> (* ??? *)]
share|improve this question

3 Answers 3

up vote 9 down vote accepted
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

share|improve this answer
    
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

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

share|improve this answer

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_, colMax_] := Function[Evaluate[RGBColor @@ MapThread[
      Expand[InterpolatingPolynomial[{{0, #1}, {1, #2}}, \[FormalX]]] &,
      List @@@ (ColorConvert[#, RGBColor] & /@ {colMin, colMax})] /. \[FormalX] -> #]]

Examples:

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

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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