5
$\begingroup$

If I have a function, for example:

p1 = Plot[Evaluate[S[t]*10^-12 /. sol], {t, 20 10^-9, 49 10^-9}]

and this function is setting options->Automatic so the function arguments are implicitly:

p1 = Plot[Evaluate[S[t]*10^-12 /. sol], {t, 20 10^-9, 49 10^-9}, 
          PlotPoints->Automatic, MaxRecursion->Automatic]

how do I get the value to which Automatic has been set?

$\endgroup$
  • $\begingroup$ You can look at Options[p1] although this can sometime also show Automatic for some of internal options. $\endgroup$ – Nasser Nov 30 '14 at 0:37
  • $\begingroup$ @Nasser That will only tell me that an option has been set to Automatic. I want to know what that value is. $\endgroup$ – Sean Bearden Nov 30 '14 at 0:39
  • 3
    $\begingroup$ It should be AbsoluteOptions[p1, PlotPoints], but AbsoluteOptions[] has a lot of bugs and doesn't work for PlotPoints $\endgroup$ – Dr. belisarius Nov 30 '14 at 0:45
  • $\begingroup$ @belisarius AbsoluteOptions[p1, PlotPoints] returns empty for p1 = Plot[Sin[x], {x, 0, Pi}, PlotPoints -> Automatic] on windows, V 10.01. So you are right, it has a bug. $\endgroup$ – Nasser Nov 30 '14 at 0:49
7
$\begingroup$

Another option is to use Trace to find occurrences of the relevant rules which appear during evaluation:

Trace[
 Plot[Sin[t], {t, 0, 2 Pi}],
 HoldPattern[PlotPoints | MaxRecursion -> _],
 TraceInternal -> True] // Flatten // Union

{MaxRecursion -> 6, MaxRecursion -> Automatic, PlotPoints -> 50, PlotPoints -> Automatic}

Or you can set "Verbose" -> True in the system visualisation options to get lots of internal information as the plot is created:

SetSystemOptions["VisualizationOptions" -> {"Verbose" -> True}]
Plot[Sin[t], {t, 0, 2 Pi}]

(0.): >>>>>>>>>>>>>>> Plot <<<<<<<<<<<<<<<

(0.): Expr to Evaluate:

{Sin[t],{{t,0,2π}, Mesh->None, Exclusions->Automatic, PlotPoints->50, MaxRecursion->6, Filling->None, ColorFunction->...

$\endgroup$
7
$\begingroup$
$Version

"10.0 for Mac OS X x86 (64-bit) (September 10, 2014)"

From the documentation at http://reference.wolfram.com/language/tutorial/Options.html the default for PlotPoints is 50.

To determine the default for MaxRecursion, let

f[x_] = Product[x + n (-1)^n, {n, -4, 5}] E^(-x^2/2);

The number of points for the Plot of f[x] with the defaults for PlotPoints and MaxRecursion is

auto = Cases[Plot[f[x], {x, -5, 4}, PlotRange -> All], 
   Line[pts_] :> Length[pts], Infinity][[1]]

1154

With the default PlotPoints and varying MaxRecursion check for the same number of points:

Select[
 Cases[
     Plot[f[x], {x, -5, 4},
      PlotRange -> All,
      MaxRecursion -> #],
     Line[pts_] :> {#, Length[pts]},
     Infinity][[1]] & /@ Range[15],
 #[[2]] == auto &]

{{6, 1154}}

Hence, the default MaxRecursion is 6

$\endgroup$
  • $\begingroup$ I remembered now the Cases[...Line[pts_] method. I forgot all about it before. Much better than using index. $\endgroup$ – Nasser Nov 30 '14 at 5:01
3
$\begingroup$

When all else fail, i.e. Options[p1] or AbsoluteOptions[p1, PlotPoints], you can always grab the Line itself and find how many points it has:

 p1 = Plot[Sin[x], {x, 0, Pi}, PlotPoints -> Automatic]

Mathematica graphics

 line = p1[[1, 1, 3, 2]];
 Graphics[line]

Mathematica graphics

Length[line[[1]]]

Mathematica graphics

So, 259 points are used in this case.

 ListPlot[line[[1]], Mesh -> All, PlotStyle -> Red]

Mathematica graphics

You can see that M oversamples where the function changes most, as expected. ps. this is not the recommended way to find number of points used, since internal data structure can change, and index used above can become invalid in future versions.

$\endgroup$
  • $\begingroup$ @belisarius I am not following you, sorry. Let me think. I need coffee. But what I see is more points are used where the function changes most. (I mean near the top) $\endgroup$ – Nasser Nov 30 '14 at 1:02
  • $\begingroup$ Get your coffee. The function is almost flat at the top. $\endgroup$ – Dr. belisarius Nov 30 '14 at 1:06
  • $\begingroup$ @Nasser This helps, but I still would like to know the value of MaxRecursion->Automatic. Please let me know if you have any ideas. $\endgroup$ – Sean Bearden Nov 30 '14 at 1:10
  • $\begingroup$ @Nasser Actually, I think this method doesn't return the value of PlotPoints, rather PlotPoints*(MaxRecursion+1). $\endgroup$ – Sean Bearden Nov 30 '14 at 1:36
  • $\begingroup$ Sorry, that gives the maximum number of points used in the plot. The code: Length[line[[1]]], will give a value between PlotPoints and PlotPoints*(MaxRecursion+1)...I think. $\endgroup$ – Sean Bearden Nov 30 '14 at 1:44

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.