Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the following code:

ContourPlot[
(2.7` (-3.8099999999999996` + 7.24` x - 3.24` x^2 + 3.62` y - 6.48` x y + 6.48` x^2 y))/
( 11.43` - 6.48` x + 3.24` x^2 - 3.24` y + 6.48` x y) - 
( 3 (-(-1 + x)^2 + (1 + 2 (-1 + x) x) y))/( 3 + (-2 + x) x + (-1 + 2 x) y) , 
{x, 0.5, 1}, {y, 0, 0.5},
 ContourStyle -> {Black, Thick}, Contours -> {0}, 
 ColorFunction -> 
(If[#1 > 0, Directive[Lighter[Lighter[Lighter[Yellow]]]], White] &)]

which gives me

enter image description here

But my color function should color the area above the black line white while color area below the black line yellow.

However, if I use the colorfunction Rainbow, then it will give me the correct coloring result:

enter image description here

What should I do to make my 1st color function behave as expected?

share|improve this question
    
Your code gives what you expected when I run it on V9.0.1 on OS X 10.6.8. –  m_goldberg Jul 16 '13 at 4:25
    
It also works as expected on V8.0.4 on OS X 10.7.5. What platform is your problem arising on? –  Jens Jul 16 '13 at 5:08
    
weird... mine is V9.0.1 on OS X 10.8.4 –  wdg Jul 16 '13 at 5:17
    
@m_goldberg,@Jens, please try the updated code. Something was lost in the earlier code. –  wdg Jul 16 '13 at 5:57

3 Answers 3

up vote 7 down vote accepted

I always forget about ColorFunctionScaling too:

ContourPlot[(2.7` (-3.8099999999999996` + 7.24` x - 3.24` x^2 + 3.62` y - 6.48` x y + 
            6.48` x^2 y))/(11.43` - 6.48` x + 3.24` x^2 - 3.24` y + 6.48` x y) - (
            3 (-(-1 + x)^2 + (1 + 2 (-1 + x) x) y))/(3 + (-2 + x) x + (-1 + 2 x) y),
            {x, 0.5, 1}, {y, 0, 0.5}, 
    ContourStyle -> {Black, Thick}, Contours -> {0}, 
    ColorFunction -> (If[#1>0, Directive[Lighter[Lighter[Lighter[Yellow]]]], White] &), 
    ColorFunctionScaling -> False]

enter image description here

share|improve this answer
    
+1 You were a little faster than me, it seems... –  Jens Jul 16 '13 at 6:19

The argument to the ColorFunction shouldn't be scaled, because if it is then the zero passed to the ColorFunction depends on whether the minimum and maximum of the plot values are symmetric with respect to zero or not.

So we have to add the option ColorFunctionScaling -> False to the ContourPlot as follows:

ContourPlot[(2.7` (-3.8099999999999996` + 7.24` x - 3.24` x^2 + 
       3.62` y - 6.48` x y + 6.48` x^2 y))/(11.43` - 6.48` x + 
     3.24` x^2 - 3.24` y + 
     6.48` x y) - (3 (-(-1 + x)^2 + (1 + 2 (-1 + x) x) y))/(3 + (-2 + 
        x) x + (-1 + 2 x) y), {x, 0.5, 1}, {y, 0, 0.5}, 
 ContourStyle -> {Black, Thick}, Contours -> {0}, 
 ColorFunction -> (If[#1 > 0, 
     Directive[Lighter[Lighter[Lighter[Yellow]]]], White] &), 
 ColorFunctionScaling -> False]

This produces the correct result.

share|improve this answer

This is more of very long comment than an answer, but I hope it cast more murk on the problem.

If I evaluate

ContourPlot[
  (2.7` (-3.8099999999999996` + 7.24` x - 3.24` x^2 + 3.62` y - 6.48` x y + 6.48` x^2 y))/
    (11.43` - 6.48` x + 3.24` x^2 - 3.24` y + 6.48` x y) - 
    (3 (-(-1 + x)^2 + (1 + 2 (-1 + x) x) y))/(3 + (-2 + x) x + (-1 + 2 x) y),
  {x, 0.5, 1}, {y, 0, 0.5}, 
  ContourStyle -> {Black, Thick}, 
  Contours -> {0}, 
  ColorFunction -> (If[#1 > 0, Directive[Lighter[Lighter[Lighter[Yellow]]]], White] &)]

I getenter image description here

all.yellow.png

However, If I change -3.8099999999999996` to -3.81` and only that and then evaluate

ContourPlot[
  (2.7` (-3.81` + 7.24` x - 3.24` x^2 + 3.62` y - 6.48` x y + 6.48` x^2 y))/
    (11.43` - 6.48` x + 3.24` x^2 - 3.24` y + 6.48` x y) - 
    (3 (-(-1 + x)^2 + (1 + 2 (-1 + x) x) y))/(3 + (-2 + x) x + (-1 + 2 x) y),
  {x, 0.5, 1}, {y, 0, 0.5}, 
  ContourStyle -> {Black, Thick}, 
  Contours -> {0}, 
  ColorFunction -> (If[#1 > 0, Directive[Lighter[Lighter[Lighter[Yellow]]]], White] &)]

I get

yellow.white.png

So both of the previously posted answers may be right, but they don't seem to tell the whole story.

share|improve this answer
    
Nice observation. What leads to this difference? –  wdg Jul 17 '13 at 9:17
    
@wdg. I'd like to know the answer to that myself. It seems very strange behavior on the part of Mathematica. –  m_goldberg Jul 17 '13 at 13:24
    
I tried to compare evaluation trace but my laptop response was an attempt to fly away. Interesting observation :) +1. –  Kuba Jul 19 '13 at 7:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.