RE: Color problem with listdensityplot. Please HELP
- To: mathgroup at smc.vnet.net
- Subject: [mg15597] RE: [mg15552] Color problem with listdensityplot. Please HELP
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Thu, 28 Jan 1999 04:23:27 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Nick Art wrote:
_____________________
I want to show a two dimensional data file as a color plot. I'll use
the following lines:
data=ReadList("data.txt", Number, RecordLists->True];
ListDensityPlot[data, Mesh->False, PlotRange ->{-20, 20}];
My data is in the range of -20 to 20. Now I get a nice picture showing
the data in grayscale. This is not what I want. I would like to show my
data with colors in the following form:
Blue gradient below zero
Red gradient above or equal zero
so the value of -20 should be very blue, 0 should be white and 20 should
be very red with all shades of coulors in between.
_________________
You need to use the ColorFunction option. I give you an example.
The functions (all of them?) that have a ColorFunction option look at
the range of values it needs to plot and maps the range of values onto
[0,1] where the minimum value is mapped to zero and the maximum value
is mapped to 1.
Below I define a function RedToBlue that takes a number on [0,1] and
returns RGBColor[r,g,b] and will do what you want. Then I use
ListDensityPlot to make a plot of the type you are looking for.
The only problem is that this is much slower than the default
ColorFunction. Any ideas on how to speed this up would be appreciated.
Cheers,
Ted Ersek
In[1]:=
data=Table[20.0* Cos[x^2+y^2],{x,-2,2,0.05},{y,-2,2,0.05}];
In[2]:=
RedToBlue[x_?(#>=1/2&)]:=
RGBColor[1,2-2x,2-2x]
RedToBlue[x_?(#<1/2&)]:=
RGBColor[2x,2x,1]
In[4]:=
ListDensityPlot[data, Mesh -> False,
ColorFunction:>RedToBlue];
(* DensityGraphics not shown. *)