MathGroup Archive 2007

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

Search the Archive

Re: rescale gray levels with ListDensityPlot

  • To: mathgroup at
  • Subject: [mg74452] Re: rescale gray levels with ListDensityPlot
  • From: "Szabolcs" <szhorvat at>
  • Date: Thu, 22 Mar 2007 01:06:11 -0500 (EST)
  • References: <etqo96$14k$>

On Mar 21, 8:53 am, Benoit Scheid wrote:
> Hi,
> I have a two-dimensional list of data with positive and negative values.
> I'm using ListDensityPlot and ListCoutourPlot.
> By defaullt, the range of gray levels codes the range of z-values from
> -z_min (black) to z_max (white).
> I would like to have the zero gray level (black) for z=0 and the maximum
> gray level (white) for z=|zmax|. At the same time, I would like to use
> two different colors to discriminate between positive and
> negative values. Is that possible?
> Thanks,
> Ben

Yes, it is possible. You can define your own function that transforms
values to colours. Look up ColorFunctionScaling and ColorFunction in
the help browser. Define the colour function using RGBColor,
GrayLevel, Hue or CMYKColor. Here is an example:

DensityPlot[Sin[x]*Sin[y], {x, -Pi, Pi}, {y, -Pi, Pi},
  ColorFunctionScaling -> False,
  ColorFunction -> (If[# > 0, Hue[0, 1 - #, #], Hue[0.5, 1 + #, -#]]
& )]

Not that if ColorFunctionScaling -> False (which you need to
distinguish between positive and negative values), you need to take
care of scaling the data values to a range suitable for Hue[ ]. In the
above example all values are between -1..1 so it was sufficient to
negate the negative ones.

  • Prev by Date: Advice for writing small Scheme interpreter
  • Next by Date: Re: Membrane
  • Previous by thread: rescale gray levels with ListDensityPlot
  • Next by thread: Re: rescale gray levels with ListDensityPlot