Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving automatically-generated plot range

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.

like image 396
Cassini Avatar asked Jan 16 '12 00:01

Cassini


2 Answers

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.}}
like image 146
Mike Honeychurch Avatar answered Oct 18 '22 10:10

Mike Honeychurch


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]

like image 32
acl Avatar answered Oct 18 '22 08:10

acl