 
 
 
 
 
 
Re: ColorFunction in DensityPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg14100] Re: ColorFunction in DensityPlot
- From: sidles at u.washington.edu (John Sidles)
- Date: Fri, 25 Sep 1998 03:15:25 -0400
- Organization: University of Washington, Seattle
- References: <6u87rm$4p3@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <6u87rm$4p3 at smc.vnet.net>,
Selwyn Hollis  <shollis at peachnet.campus.mci.net> wrote:
>Let's say we're solving the heat equation on [0,1]x[0,1] numerically
>with an initial temperature distribution with values in [0,1], and
>we're displaying the solution with ListDensityPlot as it evolves over
>time. How can one specify the ColorFunction option in ListDensityPlot
>so that a temperature of 1 _always_ shows as red and a temperature of 0
>always shows as blue (with green, yellow, orange in between)? In other
>words, I need a fixed mapping between function values and color.
>
>Thanks!
>Dr. Selwyn Hollis
Dear Dr. Hollis 
This is very easy to do.  Here's a routine which should do exactly what
you want ...
In[1]:= <<Graphics`Colors`;
In[2]:= 
   myColorFunction[t_] := Module[
        { trimmedTemp,
          tempMin=0.0,  (* adjust to your needs *)
          tempMax=1.0,  (* adjust to your needs *)
          hlsHue },
          
          trimmedTemp = Min[tempMax,Max[tempMin,t]];
          (* The scaling below gives red at tempMin, blue at tempMax *)
          (* You can easily adjust it for other color wheel spans *)
          (* Also, try varying the lightness and saturation values *)
          hlsHue = 2/3 * (tempMax-trimmedTemp)/(tempMax-tempMin);
          HLSColor[hlsHue,0.5,1.0]
       ];
Here's an example of the output of this color function:
        
In[3]:= myColorFunction[0.1]
Out[3]= RGBColor[0.,0.4,1.]
Note that the low temperature gives a glue-green hue, as desired.
Then in your density plot, use the option
    ColorFunction -> myColorFunction
You can easily adapt the above to vary the lightness & saturation of the
colors, the range of temperatures, and the span of the color wheel you
want to cover.
Good luck!   John Sidles

