Re: question about ColorFunction
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: question about ColorFunction
- From: twj
- Date: Wed, 27 Jan 93 09:17:33 CST
>I have a two dimensional table all of whose elements are 0, 1, 2, or 3. I am
>trying to create a ListDensityPlot with a different color assigned to each of
>these four values. The following does not display four colors as I had
>expected. Does anyone know where I went wrong?
>
>In[1]:= colormap[f_] := Switch[Floor[f],
> 0,RGBColor[.25,1,.25],
> 1,RGBColor[1,0,1],
> 2,RGBColor[0,1,1],
> 3,RGBColor[0,0,1]]
>
>In[2]:= table = Table[Mod[x+y,4],{x,0,10},{y,0,10}];
>
>In[3]:= ListDensityPlot[table, Mesh -> False,
> ColorFunction -> (colormap[#]&)];
The problem here is that the arguments provided to ColorFunction are
scaled to be in the range 0 to 1.
The colormap function should thus be written as such:
colormap[f_] := Which[ f < .25, RGBColor[.25,1,.25],
f < .5, RGBColor[1,0,1],
f < .75, RGBColor[0,1,1],
True ,RGBColor[0,0,1]]
Also when you use this colormap you don't need to make it into a pure function
since it already is a function of one argument.
ListDensityPlot[table, Mesh -> False,
ColorFunction -> colormap]
Tom Wickham-Jones
Wolfram Research Inc.