MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: RE: Fill the space surrounded by two contours lines with different colors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36496] RE: [mg36458] RE: [mg36422] Fill the space surrounded by two contours lines with different colors
  • From: "DrBob" <drbob at bigfoot.com>
  • Date: Mon, 9 Sep 2002 00:29:41 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

This might be a convenient way of defining color functions:

ClearAll[cfun]
cfun[colors_List, brkPts_List] /; Length@colors == Length@brkPts :=
    Function[z,
      Which @@ Sequence@Flatten@Transpose[{Less[z, #] & /@ brkPts,
colors}]]

colors = {White, RoyalBlue, White, Red, White};
brkPts = {-0.6, -0.42, 0.4, 0.6, Infinity};
ContourPlot[f[x, y], {
    x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 30, ColorFunctionScaling ->
False, 
ColorFunction -> cfun[colors, brkPts], Contours -> contourvalues];


colors = {Yellow, Peru, Salmon, Apricot, HotPink, Linen};
brkPts = {-0.6, -0.42, 0.2, 0.4, 0.6, Infinity};
Timing[ContourPlot[f[x, y], {x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 30,
      ColorFunctionScaling -> False, ColorFunction -> cfun[colors,
brkPts], 
      Contours -> contourvalues];]

Bobby Treat

-----Original Message-----
From: David Park [mailto:djmp at earthlink.net] 
To: mathgroup at smc.vnet.net
Subject: [mg36496] [mg36458] RE: [mg36422] Fill the space surrounded by two
contours lines with different colors


Jun Lin,

Here is an example.

Needs["Graphics`Colors`"]

Let's make a contour plot of this function.

f[x_, y_] := Sin[x]Sin[2y]

Let's specify the exact contours to use. I got rid of the 0. contour
because
it is difficult to obtain in this plot.

contourvalues = Complement[Range[-1, 1, 0.2], {0.}]
{-1, -0.8, -0.6, -0.4, -0.2, 0.2, 0.4, 0.6, 0.8, 1.}

Now we define a ColorFunction for the plot. I actually colored two
different
bands to show how you can make a general color function to give each
band a
desired color.

cfun[z_] :=
  Which[
    -0.6 < z < -0.42, RoyalBlue,
    0.4 < z < 0.6, Red,
    True, White]

ContourPlot[f[x, y], {x, 0, Pi}, {y, 0, Pi},
    PlotPoints -> 30,
    ColorFunctionScaling -> False,
    ColorFunction -> cfun,
    Contours -> contourvalues];

Using the option ColorFunctionScaling -> False says that the z value
will be
the actual value of f[x,y]. Otherwise, in general, it will be scaled
between
0 and 1. It is easier to write a color function when z is the actual
value
of the function.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


From: Jun Lin [mailto:jl_03824 at yahoo.com]
To: mathgroup at smc.vnet.net

I need to fill the space between two contour lines, C1 and C2, with
red color, and leave the other place white. What trick I have to use?
Any suggestion and advice will be appreciated.

Jun Lin







  • Prev by Date: RE: Re: word processing with mathematica
  • Next by Date: RE: word processing with mathematica
  • Previous by thread: RE: Fill the space surrounded by two contours lines with different colors
  • Next by thread: word processing with mathematica