data = Table[N[Exp[-x^2 - y^2]*x], {y, -2, 2, 0.05}, {x, -2, 2, 0.05}];
{zmin, zmax} = {Min[#], Max[#]} & [Flatten[data]];
colorf[sz_] := Module[{z}, z = (zmax - zmin)*sz + zmin;
Which[
z < -0.3, RGBColor[1, 0,
0],
z < -0.15, RGBColor[1, 1,
0],
z < 0, RGBColor[0, 1, 0],
z < 0.15, RGBColor[0, 1,
1],
z < 0.3, RGBColor[0, 0, 1],
True, RGBColor[1, 0, 1]
]]
ListContourPlot[data, Contours -> {-0.3, -0.15, 0.15, 0.3},
ColorFunction -> colorf]
works fine.
Regards
Jens
>Is the a way to assign specific colors to the intervals between individual
>
>contours?
>
ListContourPlot[
Table[x^2+y^2+Random[Real,{-0.2,0.2}],
{x,-2,2,0.1},{y,-2,2,0.1}],
ContourStyle->RGBColor[0,0,1]];
ListContourPlot[
Table[x^2+y^2+Random[Real,{-0.2,0.2}],
{x,-2,2,0.1},{y,-2,2,0.1}],
ContourStyle->{{RGBColor[0,0,1]},{RGBColor[1,0,0]}}];
ListContourPlot[
Table[x^2+y^2+Random[Real,{-0.2,0.2}],{x,-2,2,0.1},{y,-2,2,0.1}],
ContourStyle->Join[
Table[{RGBColor[0,0,1]},{2}],
{RGBColor[1,0,0]}]];
Bob Hanlon
Chantilly, VA USA
ListContourPlot[
Table[x^2 + y^2 + Random[Real, {-0.2, 0.2}],
{x, -2, 2, 0.1}, {y, -2, 2, 0.1}],
ColorFunction -> (Hue[1 - #1] &)];
I added a rule for the option 'ColorFunction'. For the options
avalable in 'ListContourPlot' you should refer to 'ContourGraphics'.
Best,
Anton
==============================================================
Anton Antonov Antonov, PhD ***** Wolfram Research Inc.
http://www.imm.dtu.dk/~uniaaa *** tel +1 217 398 0700 #782
==============================================================
Give me wings and I will crawl faster!
--------------------------------------------------------------
On Wed, 7 Nov 2001 Moranr...@aol.com wrote:
> Is the a way to assign specific colors to the intervals between individual
> contours?
Yes, you can explicitly color each contour range. Here is an example. I used
a ContourPlot instead of a ListContourPlot to save the extra steps of
generating a set of data.
Needs["Graphics`Colors`"]
colfun[contourvals_, colorlist_][z_] := Module[{i},
If[z > Last[contourvals], Return[Last[colorlist]]];
i = 1;
While[z > contourvals[[i]], i++];
colorlist[[i]]]
contourvals = Range[0.2, 0.8, 0.1];
colorlist = {Gray, RoyalBlue, AureolineYellow, RoyalBlue, AureolineYellow,
RoyalBlue, AureolineYellow, Gray};
ContourPlot[Sin[x]Sin[y], {x, 0, Pi}, {y, 0, Pi},
Contours -> contourvals,
ColorFunction -> colfun[contourvals, colorlist],
ColorFunctionScaling -> False,
PlotPoints -> 25,
ImageSize -> 400];
I will comment on several techniques I used in this plot.
1) I needed to give the contour values explicitly since the color function
uses them.
2) I used ColorFunctionScaling -> False so that the z values that
Mathematica feeds to the color function are the actual values. Otherwise
Mathematica scales the z values from 0 to 1, which will not generally be
what you want.
3) I picked out only a subrange of contours to plot. Low and high values
were colored Gray. The color list should contain one more entry than the
contour values list. The first and last items are the under and over value
colors.
David Park
dj...@earthlink.net
http://home.earthlink.net/~djmp/
John,
Here is a way:
Notebook[{
Cell[CellGroupData[{
Cell["Specifying the colors of contour regions", "Subsubsection"],
Cell[TextData[{
"Suppose that we wish to draw several contour plots with ",
StyleBox["Contours \[Rule] {z",
FontFamily->"Courier"],
StyleBox["1",
FontFamily->"Courier",
FontVariations->{"CompatibilityType"->"Subscript"}],
StyleBox[",z",
FontFamily->"Courier"],
StyleBox["2",
FontFamily->"Courier",
FontVariations->{"CompatibilityType"->"Subscript"}],
StyleBox[",..}",
FontFamily->"Courier"],
"and have the same colors correspond to the same height intervala. \
The following function will construct an appropriate color function. \
Note that this only works if we set\n",
StyleBox["ColorFunctionScaling\[Rule]False",
FontFamily->"Courier"],
" in ",
StyleBox["ContourPlot",
FontFamily->"Courier"],
"."
}], "Text"],
Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"MakeColorFunction", "[",
RowBox[{
RowBox[{"cntrs_", "?", "OrderedQ"}], ",", " ", "clrs_"}],
"]"}], "/;",
RowBox[{
RowBox[{"Length", "[", "clrs", "]"}], "==",
RowBox[{
RowBox[{"Length", "[", "cntrs", "]"}], "+", "1"}]}]}], ":=",
"\[IndentingNewLine]",
RowBox[{"Function", "@@",
RowBox[{"{",
RowBox[{"Which", "@@",
RowBox[{"Flatten", "[",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"#", "\[LessEqual]", " ",
RowBox[{"cntrs", "[",
RowBox[{"[", "1", "]"}], "]"}]}], ",",
RowBox[{"clrs", "[",
RowBox[{"[", "1", "]"}], "]"}]}], "}"}], ",",
RowBox[{"Table", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{
RowBox[{"cntrs", "[",
RowBox[{"[", "i", "]"}], "]"}], "<",
"#", "\[LessEqual]",
RowBox[{"cntrs", "[",
RowBox[{"[",
RowBox[{"i", "+", "1"}], "]"}],
"]"}]}], ",",
RowBox[{"clrs", "[",
RowBox[{"[",
RowBox[{"i", "+", "1"}], "]"}], "]"}]}],
"}"}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",", " ",
RowBox[{
RowBox[{"Length", "[", "cntrs", "]"}],
"-", "1"}]}], "}"}]}], "]"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{
RowBox[{"cntrs", "[",
RowBox[{"[",
RowBox[{"-", "1"}], "]"}], "]"}],
"\[LessEqual]", "#"}], ",",
RowBox[{"clrs", "[",
RowBox[{"[",
RowBox[{"-", "1"}], "]"}], "]"}]}], "}"}]}],
"}"}], "\[IndentingNewLine]", "]"}]}],
"}"}]}]}]], "Input"],
Cell["For example, we get", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"MakeColorFunction", "[",
RowBox[{
RowBox[{"{",
RowBox[{"z1", ",", "z2", ",", "z3"}], "}"}], ",",
RowBox[{"{",
RowBox[{"c1", ",", "c2", ",", "c3", ",", "c4"}], "}"}]}],
"]"}]], "Input"],
Cell[BoxData[
RowBox[{
RowBox[{"Which", "[",
RowBox[{
RowBox[{"#1", "\[LessEqual]", "z1"}], ",", "c1", ",",
RowBox[{"z1", "<", "#1", "\[LessEqual]", "z2"}], ",", "c2",
",",
RowBox[{"z2", "<", "#1", "\[LessEqual]", "z3"}], ",", "c3",
",",
RowBox[{"z3", "\[LessEqual]", "#1"}], ",", "c4"}], "]"}],
"&"}]], "Output"]
}, Open ]],
Cell["Let's make a plot.", "Text"],
Cell[BoxData[
RowBox[{"<<", "Graphics`Colors`"}]], "Input"],
Cell[BoxData[{
RowBox[{
RowBox[{"cntrs", "=", " ",
RowBox[{"{",
RowBox[{
RowBox[{"-", ".9"}], ",",
RowBox[{"-", ".6"}], ",",
RowBox[{"-", ".3"}], ",", "0", ",", ".3", ",", ".6", ",",
".9"}], "}"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"clrs", " ", "=", " ",
RowBox[{"{",
RowBox[{
"Red", ",", "Blue", ",", "LightSeaGreen", ",",
"YellowBrown", ",", "Khaki", ",", "Green", ",", " ",
"Purple", ",", "Yellow"}], "}"}]}], ";"}]}], "Input"],
Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"ContourPlot", "[",
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"Cos", "[", "x", "]"}], "+",
RowBox[{"Sin", "[", "y", "]"}]}], ")"}], "/", "2"}],
",",
RowBox[{"{",
RowBox[{"x", ",", "0", ",",
RowBox[{"2", "Pi"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{"y", ",", "0", ",",
RowBox[{"2", "Pi"}]}], "}"}], ",",
"\[IndentingNewLine]",
RowBox[{"Contours", "\[Rule]", " ", "cntrs"}], ",",
"\[IndentingNewLine]",
RowBox[{"ColorFunction", " ", "\[Rule]", " ",
RowBox[{"(",
RowBox[{"MakeColorFunction", "[",
RowBox[{"cntrs", ",", "clrs"}], "]"}], ")"}]}], ",",
"\[IndentingNewLine]",
RowBox[{
"ColorFunctionScaling", " ", "\[Rule]", "False"}]}],
"]"}], ";"}], "\[IndentingNewLine]"}]], "Input"],
Cell[BoxData[
RowBox[{
RowBox[{"dat", " ", "=", " ",
RowBox[{"Table", "[",
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"Cos", "[", "x", "]"}], "+",
RowBox[{"Sin", "[", "y", "]"}]}], ")"}], "/", "2"}],
",",
RowBox[{"{",
RowBox[{"x", ",", "0", ",",
RowBox[{"2", "Pi"}], ",", " ",
RowBox[{"Pi", "/", "10"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{"y", ",", "0", ",",
RowBox[{"2", "Pi"}], ",",
RowBox[{"Pi", "/", "10"}]}], "}"}]}], "]"}]}],
";"}]], "Input"],
Cell[BoxData[
RowBox[{
RowBox[{"ListContourPlot", "[",
RowBox[{"dat", ",", "\[IndentingNewLine]",
RowBox[{"Contours", "\[Rule]", " ", "cntrs"}], ",",
"\[IndentingNewLine]",
RowBox[{"ColorFunction", " ", "\[Rule]", " ",
RowBox[{"(",
RowBox[{"MakeColorFunction", "[",
RowBox[{"cntrs", ",", "clrs"}], "]"}], ")"}]}], ",",
"\[IndentingNewLine]",
RowBox[{"ColorFunctionScaling", " ", "\[Rule]", "False"}]}],
"]"}], ";"}]], "Input"]
}, Open ]]
},
FrontEndVersion->"4.1 for Microsoft Windows",
ScreenRectangle->{{0, 1024}, {0, 723}},
WindowSize->{694, 668},
WindowMargins->{{146, Automatic}, {-23, Automatic}},
ShowCellLabel->False
]
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
h...@haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
Needs["Graphics`Colors`"];
cf[x_] := Which[
x >.5, Red,
x > .3, Orange,
x > .1, Yellow,
x > 0.05, Green,
True, Blue
];
ListContourPlot[
Table[x^2+y^2+Random[Real,{-0.2,0.2}],
{x,-2,2,0.1},{y,-2,2,0.1}],
ColorFunction -> cf];
In a message dated 2001/11/7 6:43:12 AM, writes:
>
>In a message dated 2001/11/7 5:46:57 AM, Moranr...@aol.com writes:
>
>>Is the a way to assign specific colors to the intervals between individual
>>
>>contours?
>>
>