Skip to main content
2 of 3
edited tags
MarcoB
  • 67.7k
  • 18
  • 96
  • 198

Why does Plot3D appear to traverse the points twice?

While plotting a slow to evaluate function and trying to get some sense of progress, I noticed that Mathematica traverses the grid of points twice. Here's the reduced example:

points = {};
Dynamic[Show[
  ListPlot[Take[points, Max[0, Length@points - 5]], 
   PlotRange -> All],
  ListPlot[Take[points, -Min[Length@points, 5]], PlotRange -> All, 
   PlotStyle -> Directive[PointSize[Large], Opacity[0.1], Red]],
  AspectRatio -> Automatic]]

Monitor[Plot3D[Pause[0.05]; 0, {a, -5, 5}, {b, -5, 5}, 
  PlotRange -> All, PlotPoints -> 10, MaxRecursion -> 0], 
 AppendTo[points, {a, b}];]

If you watch the plot, you'll see that the red points move twice over the grid. If you inspect the plots variable after plotting, you'll see that not all the points are duplicates: some are offset from their originals by $\sim10^{-8}$.

Why does Plot3D do this, even though I asked for MaxRecursion->0? Is there any way to convince it to only scan the function once (not having to resort to ListPlot3D+Table)?

Ruslan
  • 7.2k
  • 1
  • 23
  • 53