RE: ListContourPlot Color

• To: mathgroup at smc.vnet.net
• Subject: [mg31505] RE: [mg31474] ListContourPlot Color
• From: "David Park" <djmp at earthlink.net>
• Date: Thu, 8 Nov 2001 04:55:16 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```John,

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

> From: Moranresearch at aol.com [mailto:Moranresearch at aol.com]
To: mathgroup at smc.vnet.net
>
> Is the a way to assign specific colors to the intervals between
> individual
> contours?
> Thank you. John R Moran PhD,MD
>

```

• Prev by Date: Re: 2nd order differential equation help
• Next by Date: Re: Limit question
• Previous by thread: Re: ListContourPlot Color
• Next by thread: Re: ListContourPlot Color