MathGroup Archive 2005

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

Search the Archive

Re: Does ContourPlot behave correctly?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59885] Re: Does ContourPlot behave correctly?
  • From: Peter Pein <petsie at dordos.net>
  • Date: Wed, 24 Aug 2005 06:32:34 -0400 (EDT)
  • References: <deeo93$38f$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Vladislav schrieb:
> Hello,
> 
> I try two commands, the only difference being .9 in lieu of .5 in the
> Contours option.
> 
> ContourPlot[Exp[-(x^2 +
>     y^2)/2], {x, -1, 1}, {y, -1, 1},
>       Contours -> {.39, .5, .95},
>       ColorFunction -> (
>       GrayLevel[#1] &), PlotPoints -> 100];
> 
> ContourPlot[Exp[-(x^2 +
>     y^2)/2], {x, -1, 1}, {y, -1, 1},
>       Contours -> {.39, .9, .95},
>       ColorFunction -> (GrayLevel[#1] &),
>       PlotPoints -> 100];
> 
> 
> I obtain two different plots. The smallest circle is the same for the
> two pictures, it is OK becouse it corresponds to the Contor at 0.95.
> 
> I expected to have 3 circle on the two pictures with the only
> difference in the second circle at .9 or .5. In reallity, I have only
> two circles in the first plot and three circles in the second one.
> Moreover the external contour at .39 is not the same in the two
> pictures.
> 
> Can anybody explain or justify this behavoir?
> 
> Vlad
> 

Hi Vlad,

in fact you've got three disks in both plots, but ColorFunctionScaling
makes the difference between the corners and the large disk nearly
invisible (try ContourShading->False to verify the contourlines).

The selection of the color of the region between 2 contours seems to be
related to the mean of this region's upper and lower boundary. To get
the same color for the outer region and the large disk in both plots, I
had nothing better than building a comparison table from the list of
contourlevels and to take the first value from this table that is
smaller or equal to the height of the point beeing plotted:

cpl[cl_List] :=
  Module[{compare = Sort[Flatten[{0, cl, 1}], Greater]},
   ContourPlot[E^((-(1/2))*(x^2 + y^2)), {x, -1, 1}, {y, -1, 1},
   Contours -> cl, ColorFunction ->
     (GrayLevel @@ Cases[compare, x_ /; x <= #1, 1, 1] & ),
   ColorFunctionScaling -> False, PlotPoints -> 100]
];

Now the large disk will get the same color in both plots:

Show[GraphicsArray[Block[{$DisplayFunction = #1 & },
    cpl /@ {{0.39, 0.5, 0.95}, {0.39, 0.9, 0.95}}]],
  ImageSize -> {700, 350}];

-- 
Peter Pein, Berlin
GnuPG Key ID: 0xA34C5A82
http://people.freenet.de/Peter_Berlin/


  • Prev by Date: Re: List Replace Problems
  • Next by Date: Re: Does ContourPlot behave correctly?
  • Previous by thread: Re: Does ContourPlot behave correctly?
  • Next by thread: Re: Does ContourPlot behave correctly?