Is it possible to retrieve an automatically-generated plot range in Mathematica?
For example, if I were to do:
Plot[Sin[x], {x, 0, 2 \[Pi]}, PlotRange -> Automatic]
then I'd like to know that the range of the Y axis was -1 to 1 and the range of the X axis was 0 to 2 pi.
p = Plot[Sin[x], {x, 0, 2*Pi}, PlotRange -> Automatic];
AbsoluteOptions is a bit of a lottery but works in this case
AbsoluteOptions[p, PlotRange]
{PlotRange -> {{0., 6.28319}, {-1., 1.}}}
Even though AbsoluteOptions superceded FullOptions sometimes it is also worth trying FullOptions if and when AbsoluteOptions fails because I have come across cases when AbsoluteOptions fails but FullOptions works. In this case FullOptions also works:
FullOptions[p, PlotRange]
{{0., 6.28319}, {-1., 1.}}
Not pretty or general, but you can brute-force it likes this:
p = Plot[Sin[x], {x, 0, 2*Pi}, PlotRange -> Automatic];
First@Cases[p, List[___, Rule[PlotRange, x_], ___] -> x]
giving
{{0., 6.28319}, {-1., 1.}}
You can work this out by looking at FullForm[p]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With