[Date Index]
[Thread Index]
[Author Index]
RE: ColorData as a Funnction of height values
*To*: mathgroup at smc.vnet.net
*Subject*: [mg93240] RE: [mg93220] ColorData as a Funnction of height values
*From*: "David Park" <djmpark at comcast.net>
*Date*: Sat, 1 Nov 2008 05:05:42 -0500 (EST)
*References*: <18277846.1225441934632.JavaMail.root@m02>
Here is a sample set of data. I am going to uses a case that is general
enough so that you should be able to use it as a model for your own data.
data = Flatten[
Table[{x, y, Sin[x^2 + y^2]}, {x, -2, 2, 0.1}, {y, -2, 2, 0.1}],
1];
First, I will use the SouthwestColors scheme, which I clicked in from the
ColorSchemes palette. It goes from a dark red to blue, and you want the
opposite. So I made the ColorFunction a pure function and used 1 - zvalue
instead of zvalue. That reverses the color direction.
Next I set ColorFunctionScaling to False so that we will work with the
actual z values of your data. Often, it is easier to work with the actual
data values. You could obtain these values by making a preliminary
ListContourPlot and looking at the contour values, or by using NMaximize and
NMinimize. Then I used the Rescale expression to rescale the minimum and
maximum z values, {-1,1} in this case, to go from 0 to 1, which are the
color gradient coordinate. So then we can make the main plot.
mainplot =
ListDensityPlot[data,
Mesh -> None,
InterpolationOrder -> 2,
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["SouthwestColors"][
1 - Rescale[#, {-1, 1}]] &),
ImageSize -> 400]
Next we make a legend. (Don't use the regular Mathematica Legend command.
It's pretty awful.) We make our own much nicer legend, by making a
ContourPlot where
Z goes from out minimum to maximum values and we pick an appropriate set of
contours. We use the same ColorFunction and Scaling as in the main plot. We
make the ticks the same as the contours and put them on whichever side we
want.
legendplot =
ContourPlot[z, {x, 0, .2}, {z, -1, 1},
AspectRatio -> Automatic,
Contours -> Range[-1., 1., .25],
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["SouthwestColors"][
1 - Rescale[#, {-1, 1}]] &),
PlotRangePadding -> 0,
FrameTicks -> {{None, Range[-1., 1., .25]}, {None, None}},
ImageSize -> {Automatic, 300}]
Now, we just combine the two plots in a Row.
Row[{mainplot, Spacer[20], legendplot}]
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark
From: olalla [mailto:operez009 at ikasle.ehu.es]
Dear all,
I have a long list of numerical values, {x,y,f(x,y)}, representing
the value of a field in the points (x,y). I want to visualize them
using ListContourPlot or ListDensityPlot. I have two poblems:
1. I want to change the colour to a usual scale of Blue-Minimum and
Red-Maximum, or to make something similar to
ColorFunction -> Function[{x, y, z}, Hue[z]]
but with my numerical data, not with a function. How can I do this?
2. When including a legend with ListContourPlot or LisDensityPlot,
how can I include the white colour which is already included in the
plot but not in the legend?
Thanks in advance
Olalla P=E9rez
UPV/EHU=
Prev by Date:
**Re: Stopping a program**
Next by Date:
**Re: Re: Hypergeometric2F1**
Previous by thread:
**Re: Stopping a program**
Next by thread:
**Sum[n^(-n), {n, 1, Infinity}]**
| |