Message Boards Message Boards

0
|
7450 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Using ColorFunction in ContourPlot?

Hello,

I must be missing something very simple, or this is a bug in ContourPlot, at least in the option ColorFunction:

ContourPlot[x^2 - y^2, {x, -3, 3}, {y, -3, 3}, Contours -> {0}, ColorFunction -> (If[#1 < 0, Red, Yellow] &), ImageSize -> 200]

enter image description here

I tried slightly different functions inside the ColorFunction. Basically I compare #1 to zero using <, >, <=, >=, and == (#1 < 0 &, #1 <= 0 &, etc.). Three of the five look wrong to me. I tried increasing PlotPoints, changed all the "0" to "0.0". Nothing helped. The use of ColorFunction is copied straight from the documentation of ContourPlot (last example under Options > ColorFunction):

Make everything red above a contour at z==1/2:
ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}, Contours -> {1/2}, ColorFunction -> (If[#1 > 1/2, Red, White] &)]

I am using Mathematica 11.0.0.0, Student Edition. I hope I am wrong.

Thanks,

OL.

POSTED BY: Otto Linsuain
3 Replies

Thanks. it is good to know I was missing something simple. I had run into that scaling thing before, but did not anticipate its effect could be so drastic. It is in that borderline where you could almost call it a bug (at my work we would), but I can live with it. Thanks.

OL.

POSTED BY: Otto Linsuain

Actually not a bug, but a feature. A very useful feature. See ColorFunction help, 2nd line (under details):

With the usual default setting ColorFunctionScaling->True, all arguments supplied to func are scaled to lie in the range 0 to 1.

and 3rd line:

With ColorFunctionScaling->False, original unscaled values are used.

POSTED BY: Sander Huisman

It has to do with the option ColorFunctionScaling:

ContourPlot[x^2 - y^2, {x, -3, 3}, {y, -3, 3}, Contours -> {0}, ColorFunction -> (If[#1 < 0, Red, Yellow] &), ImageSize -> 200, ColorFunctionScaling -> False]

This is normally set to True, causing the values that show up being scaling from 0 to 1, and then fed in to the ColorFunction.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract