0
$\begingroup$

This question already has an answer here:

How can I extract the used plot range from a plot?

I create a plot:

plot = Plot[Sin[x], {x, 0, 2 \[Pi]}, Frame -> True, 
  PlotRangePadding -> {0, Scaled[.2]}]

When I try to extract the plot range with: AbsoluteOptions or PlotRange, I incorrectly get: {{0., 6.28319}, {-1., 1.}} This misses the plot range padding.

Manually adding it

{px0, py0} = Quiet[AbsoluteOptions[plot, PlotRange]][[1, 2]];
{xpad, ypad} = 
  Map[Identity @@ # &, 
   Quiet[AbsoluteOptions[plot, PlotRangePadding]][[1, 2]], {2}];
{lx, ly} = Differences[#][[1]] & /@ {px0, py0};
{px, py} = 
 MapThread[{#1[[1]] - #3[[1]] #2, #1[[2]] + #3[[2]] #2} &, {{px0, 
    py0}, {lx, ly}, {xpad, ypad}}]

does not lead to the correct answer either. I get {{0., 6.28319}, {-1.4, 1.4}} instead of {{0., 6.28319}, {-1.666667, 1.666667}}.

$\endgroup$

marked as duplicate by Carl Woll, m_goldberg plotting Apr 23 at 22:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ @CarlWoll Yes, your GraphicsInformation paclet is one solution. However, with Mma 12 just released, is there still no simpler solution available? I did not find your solution before due to the misleading title of the other question. $\endgroup$ – Oscillon Apr 23 at 20:06
  • $\begingroup$ The source code of the paclet is explained in this question: mathematica.stackexchange.com/questions/2091/… $\endgroup$ – Oscillon Apr 24 at 7:24
0
$\begingroup$

Just do this:

Options[plot, PlotRangePadding]

{PlotRangePadding -> {{0, 0}, {Scaled[0.2], Scaled[0.2]}}}

or

enter image description here

{PlotRange -> {{0, 2 [Pi]}, {-1., 1.}}}

$\endgroup$
  • $\begingroup$ Unfortunately this does not return the correct used y plot range. It should be {-1.666667, 1.666667}, not {-1., 1.}. $\endgroup$ – Oscillon Apr 24 at 7:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.