Re: rescale gray levels with ListDensityPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg74452] Re: rescale gray levels with ListDensityPlot
- From: "Szabolcs" <szhorvat at gmail.com>
- Date: Thu, 22 Mar 2007 01:06:11 -0500 (EST)
- References: <etqo96$14k$1@smc.vnet.net>
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.