Wolfram Computation Meets Knowledge

GraphicsBounds

Contributed by: Taliesin Beynon

Get the plot range used in a piece of graphics.

ResourceFunction["GraphicsBounds"][graphics]

gives a list {{left,right}, {bottom,top}} of the coordinates that bound all graphics primitives occuring in graphics.

Details and Options

GraphicsBounds works only in 2D graphics.

Examples

Basic Examples

Display some graphics primitives:

In[1]:=
Graphics[{Red, Disk[{2, 2}], Green, Rectangle[{0, 0}, {2, 2}], Blue, Polygon[CirclePoints[7]]}]
Out[1]=

Get the plot range:

In[2]:=
ResourceFunction["GraphicsBounds"][%]
Out[2]=

Without displaying graphics:

In[3]:=
ResourceFunction["GraphicsBounds"][
 Graphics[{Red, Disk[{2, 2}], Green, Rectangle[{0, 0}, {2, 2}], Blue, Polygon[CirclePoints[7]]}, PlotRangePadding -> 0.6]]
Out[3]=

Get some plot:

In[4]:=
Plot[Evaluate[BesselJ[1, x]], {x, 0, 10}, Filling -> Axis]
Out[4]=

Get the plot range:

In[5]:=
ResourceFunction["GraphicsBounds"][%]
Out[5]=

Scope

GraphicsBounds works only with 2D graphics:

In[6]:=
ResourceFunction["GraphicsBounds"][
 Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]]
Out[6]=

Properties and Relations

You can get the same information using AbsoluteOptions:

In[7]:=
AbsoluteOptions[
 Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, Filling -> Axis], PlotRange]
Out[7]=

Resource History