MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ColorFunction in DensityPlot

  • To: mathgroup at
  • Subject: [mg14100] Re: ColorFunction in DensityPlot
  • From: sidles at (John Sidles)
  • Date: Fri, 25 Sep 1998 03:15:25 -0400
  • Organization: University of Washington, Seattle
  • References: <6u87rm$>
  • Sender: owner-wri-mathgroup at

In article <6u87rm$4p3 at>,
Selwyn Hollis  <shollis at> 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.
>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`;
   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);


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

  • Prev by Date: Notation Problem
  • Next by Date: Integral?
  • Previous by thread: ColorFunction in DensityPlot
  • Next by thread: Re: ColorFunction in DensityPlot