# How to return the value of Automatic when it is used in a Mathematica function?

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?

• You can look at Options[p1] although this can sometime also show Automatic for some of internal options. – Nasser Nov 30 '14 at 0:37
• @Nasser That will only tell me that an option has been set to Automatic. I want to know what that value is. – Sean Bearden Nov 30 '14 at 0:39
• It should be AbsoluteOptions[p1, PlotPoints], but AbsoluteOptions[] has a lot of bugs and doesn't work for PlotPoints – Dr. belisarius Nov 30 '14 at 0:45
• @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. – Nasser Nov 30 '14 at 0:49

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->...

\$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

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

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]


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


Length[line[[1]]]


So, 259 points are used in this case.

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


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.

• @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) – Nasser Nov 30 '14 at 1:02
• Get your coffee. The function is almost flat at the top. – Dr. belisarius Nov 30 '14 at 1:06
• @Nasser This helps, but I still would like to know the value of MaxRecursion->Automatic. Please let me know if you have any ideas. – Sean Bearden Nov 30 '14 at 1:10
• @Nasser Actually, I think this method doesn't return the value of PlotPoints, rather PlotPoints*(MaxRecursion+1). – Sean Bearden Nov 30 '14 at 1:36
• 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. – Sean Bearden Nov 30 '14 at 1:44