4

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?

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96

2 Answers2

7

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}}

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
0

this is not exact but close

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

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

kglr
  • 394,356
  • 18
  • 477
  • 896
  • Depends how close initial PlotRange is to the range defined by primitives inside. For PlotRange -> {-100, 300} it gives the same result. – Kuba Dec 20 '17 at 14:05