11

I met a tricky problem with ContourPlot, which is when I change the range of my variable, I get a totally new figure. For example:

ContourPlot[2.` c^4 - 1.693 c^4 x - 0.861 x^2 + 0.0417 Log[10^(-6)] x^2 + 
   0.25` x^2 Log[1/c^(2/3)] + (1.` c^4 + 0.673 x) x Log[x] - 
   0.125` x^2 Log[x]^2 == 0, {x, 3, 100}, {c, 1, 5}, PlotRange -> All]

enter image description here

But if I change the range of c from {1,5} to {1,50} the figure is different:

enter image description here

Anyone knows the reason? Which figure is correct?

István Zachar
  • 47,032
  • 20
  • 143
  • 291
3c.
  • 669
  • 1
  • 7
  • 13

2 Answers2

12

rcollyer is right about the source of the problem, but there are better (faster) ways to handle it than merely cranking up the PlotPoints. With that option alone I needed about PlotPoints -> 300 to get a smooth line, which took seven seconds to render:

eq = 2.` c^4 - 1.6931471805599454` c^4 x - 0.8611473146305157` x^2 + 
    0.041666666666666664` Log[10^(-6)] x^2 + 
    0.25` x^2 Log[1/c^(2/3)] + (1.` c^4 + 0.6732867951399863` x) x Log[x] - 
    0.125` x^2 Log[x]^2 == 0;

ContourPlot[Evaluate @ eq, {x, 3, 100}, {c, 1, 50},
  PlotRange -> All, PlotPoints -> 300] //AbsoluteTiming //Column

enter image description here

MaxRecursion helps a lot in this case:

ContourPlot[Evaluate @ eq, {x, 3, 100}, {c, 1, 50},
  PlotRange -> All,
  PlotPoints -> 75,
  MaxRecursion -> 6
] // AbsoluteTiming // Column

enter image description here

Even better here appears to be controlling the lower level MaxBend parameter:

ContourPlot[Evaluate @ eq, {x, 3, 100}, {c, 1, 50},
  PlotRange -> All,
  MaxRecursion -> 3,
  Method -> {MaxBend -> 0.5}
] // AbsoluteTiming // Column

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 2
    I've always pushed the number of PlotPoints as even with the slow-down, it seems to do the trick. Also, I tend to be leery of MaxRecursion as I've used it to shut-down my machine before. MaxBend, however, looks promising. – rcollyer Aug 26 '13 at 19:29
  • 1
    @rcollyer You're right, you do have to be careful of MaxRecursion as it can run away rather easily. – Mr.Wizard Aug 26 '13 at 19:34
9

It is a resolution problem. It can be cured by increasing the number of PlotPoints used:

Table[ContourPlot[
  2.` c^4 - 1.6931471805599454` c^4 x - 0.8611473146305157` x^2 + 
    0.041666666666666664` Log[10^(-6)] x^2 + 
    0.25` x^2 Log[
      1/c^(2/3)] + (1.` c^4 + 0.6732867951399863` x) x Log[x] - 
    0.125` x^2 Log[x]^2 == 0, {x, 3, 100}, {c, 1, 50}, 
  PlotRange -> All, PlotPoints -> pp, 
  PlotLabel -> "PlotPoints \[Rule] " <> ToString[pp] ],
 {pp, {Automatic, 150}}
 ]

enter image description here

rcollyer
  • 33,976
  • 7
  • 92
  • 191