What lead to this, is when I noticed that ListPlot3D was much slower when adding a specific InterpolationOrder->n vs. not and letting the default take care of it.

To find out why it is so much slower (timing is below), I asked Mathematica to tell me what default InterpolationOrder it used for the current plot. So I used the command

      AbsoluteOptions[p, InterpolationOrder]

To do that, which supposed to return the value used in p. From the excellent book Mathematica Navigator:

Mathematica graphics

But Mathematica gave an error and said that InterpolationOrder is not a known option for this plot. But http://reference.wolfram.com/language/ref/ListPlot3D.html shows it there.

Mathematica graphics

So my question is, how does one find what InterpolationOrder is used for current plot of ListPlot3D?

My sub question is actually (the reason why I wanted to find the above), is why ListPlot3D slows down so much when specifying this option vs. not? Here is the MWE

Clear[x, y, z];
nElem = 10; h = 1/(nElem - 1);
grid = N@Table[{i*h, j*h}, {i, -10, 10, h}, {j, -10, 10, h}];
f[x_, y_] := Sin[x*10 y] Exp[-x y];
force = Map[f[#[[1]], #[[2]]] &, grid, {2}];
p = ListPlot3D[force, InterpolationOrder -> 1, AxesLabel -> {x, y, z}]

Mathematica graphics

 AbsoluteOptions[p, InterpolationOrder]

 Timing[ListPlot3D[force, InterpolationOrder -> 1, AxesLabel -> {x, y, z}]]

 Timing[ListPlot3D[force, AxesLabel -> {x, y, z}]]
     (* 0.624004 *)

And as an extra reward, if you can answer how can one use InterpolationOrder -> 1 and still have fast plot, I will up-vote you 2 times if I can.

Version 10.0 on windows 7.

  • $\begingroup$ Do I understand that your question can be summarized as: Why is using InterpolationOrder -> 1 slower than using the default option InterpolationOrder -> None? Is it really surprising that using interpolation is slower? $\endgroup$ – Mr.Wizard Aug 28 '14 at 3:01
  • $\begingroup$ @Mr.Wizard Yes, but this is one part of it. The other part is why I get an error when query this option? I did not want to split this to 2 questions. But may be I should have. What do you think? Should they be separate? I can do that. ps. the slow down is really large as can be seen by the numbers. A bit of slow down ok, but 10 times slower? $\endgroup$ – Nasser Aug 28 '14 at 3:03

The reason that AbsoluteOptions[p, InterpolationOrder] doesn't work is that p is a Graphics object and InterpolationOrder is an option for (e.g.) ListPlot3D, not Graphics. InterpolationOrder guides the creation of the graphic but it does not remain a mutable part of it. I addressed this topic here:

As to the second question we can easily show that using interpolation plots many more points that if we do not, so it is not surprising that this takes considerably longer:

ListPlot3D[force, AxesLabel -> {x, y, z}][[1, 1]] // Length
ListPlot3D[force, AxesLabel -> {x, y, z}, InterpolationOrder -> 1][[1, 1]] // Length

| improve this answer | |
  • $\begingroup$ I see. So none of options such as PlotStyle used can be queried using AbsoluteOptions. Just tried it on normal plot: p0 = Plot[Sin[x], {x, -1, 1}, PlotStyle -> Red]; AbsoluteOptions[p0, PlotStyle] and this also gave an error. This makes AbsoluteOptions not as useful as I thought before. May be this is what the book means by "special options" in the screen shot I posted. Thanks. $\endgroup$ – Nasser Aug 28 '14 at 3:16

It is a curious thing, the default appears to do a linear interpolation ( ie. rendering more points than input ), yet specifying InterpolationOrder->1 dramatically increases the number of interpolation points:

simple example:

 data = Table[ Sin[x] , {x, 0, 10}, {y, 0, 10}] // N;

enter image description here

 in = ListPlot[ data[[All, 1]] , PlotStyle -> {PointSize[.02], Red}];
 GraphicsRow[Show[{ListPlot[#[[2 ;; 3]] & /@
     Select[  Cases[ ListPlot3D[data, InterpolationOrder -> #],
        x_List /; Length[x] > 4 , Infinity][[1]] ,
           #[[1]] == 1 & ] ], in}] & /@ {None, 1, 2}]

enter image description here

note the number of points for Interpolation->1 is the same as for ->2 (and higher)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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