4
$\begingroup$

Given some graphics expression, I would like to be able to programmatically find its PlotRange in a form of a list containing figures. I just would like to stress that the result in a form {Automatic,Automatic} or like {Automatic,{0,100}} or comparable is not what I need. Everything must be defined by numbers, such as, for example, {{0,200},{0,100}} or alike.

To be more precise, here is an expression of the type I have in mind:

expression = Show[{
   PolarPlot[300*Cos[\[CurlyPhi]/2]^2, {\[CurlyPhi], 0, \[Pi]}, 
    PlotTheme -> "Classic", PlotStyle -> Darker[Blue], 
    PlotRange -> {0, 200}, 
    TicksStyle -> Directive[Black, FontSize -> 12], 
    AxesLabel -> {Style["x", 18, Italic, "TimesNewRoman", Black], 
      Style["y", 18, Italic, "TimesNewRoman", Black]}, 
    AxesStyle -> Arrowheads[0.05], ImageSize -> 400],
   Graphics[{Text[Style["(b)", 24, "Times"], Scaled[{0.92, 0.95}]]}]}]

showing this:

enter image description here

Now, assume I have no idea of this code, but need to get its PlotRange.

Any idea?

$\endgroup$
2
  • $\begingroup$ You can take a look at this and AbsoluteOptions. If those are not enough, try to use the search. There are already questions on this. $\endgroup$
    – Lukas Lang
    Dec 20, 2017 at 13:57
  • $\begingroup$ Does this contain an answer to your question? $\endgroup$
    – Michael E2
    Dec 20, 2017 at 15:10

2 Answers 2

7
$\begingroup$

You can use my GraphicsInformation function to obtain this information. Install with:

PacletInstall[
    "GraphicsInformation",
    "Site" -> "http://raw.githubusercontent.com/carlwoll/GraphicsInformation/master"
];

Then, load it:

<<GraphicsInformation`

For your example:

GraphicsInformation[expression]
"PlotRange" /. %

{"ImagePadding" -> {{0.5, 18.}, {11.4785, 24.}}, "ImageSize" -> {400., 261.553}, "PlotRangeSize" -> {381.5, 226.074}, "ImagePaddingSize" -> {18.5, 35.4785}, "PlotRange" -> {{-44.5312, 307.031}, {-4.16667, 204.167}}}

{{-44.5312, 307.031}, {-4.16667, 204.167}}

Note that GraphicsInformation is more reliable than PlotRange. For instance, compare:

PlotRange[Graphics[{}, Axes->True]]
"PlotRange" /. GraphicsInformation[Graphics[{}, Axes->True]]

{{0., 1.}, {0., 1.}}

{{-1.04167, 1.04167}, {-1.04, 1.04}}

$\endgroup$
0
$\begingroup$

this is not exact but close

PlotRange[Graphics[expression[[1]]]]

{{-37.5, 300.}, {0., 194.856}}

$\endgroup$
1
  • $\begingroup$ Depends how close initial PlotRange is to the range defined by primitives inside. For PlotRange -> {-100, 300} it gives the same result. $\endgroup$
    – Kuba
    Dec 20, 2017 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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