# Getting axes range from plot (of the plot) [duplicate]

Related to this question in a way. After making a plot, I'd like to get the plot range (not the range of the function, but the range chosen for plotting which usually leaves some buffer room). I've tried Plot[Sin[x], {x,0,10}]//PlotRange but that instead gives what seems to be the range of the function.

## marked as duplicate by Kuba♦, user9660, Alexey Popkov, dr.blochwave, Jason B.Nov 30 '15 at 14:22

• @Kuba, I can't get the accepted answer from that post to work. If you look at the test at the end of my answer here, and replace FullRange with completePlotRange then I just get error messages. – Jason B. Nov 30 '15 at 11:46
• @JasonB I would go with Chartingget2DPlotRange@Plot[Sin[x], {x, 0, 10}] – Kuba Nov 30 '15 at 11:50
• That works, but I must say that having hidden functions just takes all the fun out of it. – Jason B. Nov 30 '15 at 11:56
• @JasonB maybe but quite often they are more stable than documented :) – Kuba Nov 30 '15 at 12:19
• @JasonB I just have checked completePlotRange (from the top of my answer in the linked thread) with the test examples at the end of your answer using Mathematica 10.3 and it works like a charm producing output similar but only approximately equal to your's without any error messages. Please try it again with fresh kernel. – Alexey Popkov Nov 30 '15 at 13:45

Your method works just find to get the PlotRange, but now you want to know what the PlotRangePadding is.

AbsoluteOptions[Show[Plot[Sin[x], {x, 0, 10}]], PlotRange]
(* {PlotRange -> {{0., 10.}, {-0.999999, 1.}}} *)
Scaled[0.02]}, {Scaled[0.05], Scaled[0.05]}}} *)


This gives the answer in terms of a scaled value, so we can write a function to get the full padded range (edited to test whether the padding is in fact scaled),

padRange[range_, padding_] := Module[{scales},
range + {-1, 1} scales First@Differences[range]
]

fullRange[plot_] :=
prange = plot // PlotRange;
]

fullRange /@ {Plot[Sin[x], {x, 0, 10}],
Plot[Sin[x], {x, 0, 10}, PlotRange -> {-2, 2}],
Plot[Sin[x], {x, 0, 10}, PlotRange -> All],
Plot[Sin[x], {x, 0, 10}, PlotRange -> {{-20.322, 2200}, {-2, 2}}]
}
(* {{{-0.2, 10.2}, {-1.1, 1.1}},
{{-0.2, 10.2}, {-2., 2.}},
{{-0.2, 10.2}, {-1.1, 1.1}},
{{-20.322, 2200.}, {-2., 2.}}} *)


This shows that if you explicitly set the PlotRange, then no padding takes place

Try this:

 Select[(Plot[Sin[x], {x, 0, 10}] // Options), #[] == PlotRange &]

(*  {PlotRange -> {{0, 10}, {-0.999999, 1.}}}  *)
`

Have fun!