Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
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 occurring in graphics. | 
Display some graphics primitives:
| In[1]:= | ![Graphics[{Red, Disk[{2, 2}], Green, Rectangle[{0, 0}, {2, 2}], Blue, Polygon[CirclePoints[7]]}]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/7f6e59054d076341.png) | 
| Out[1]= |  | 
Get the plot range:
| In[2]:= | ![ResourceFunction["GraphicsBounds"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/689a1bb728eb5058.png) | 
| 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]]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/7b7067c814aadb4a.png) | 
| Out[3]= |  | 
Get a plot:
| In[4]:= | ![Plot[Evaluate[BesselJ[1, x]], {x, 0, 10}, Filling -> Axis]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/18e44a0a21973b66.png) | 
| Out[4]= |  | 
Get the plot range:
| In[5]:= | ![ResourceFunction["GraphicsBounds"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/7d9920980e1cb315.png) | 
| Out[5]= |  | 
Use GraphicsBounds to get the plot range of a plot:
| In[6]:= | ![ResourceFunction["GraphicsBounds"][
 Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, Filling -> Axis]]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/4542bcf020d9f2b6.png) | 
| Out[6]= |  | 
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]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/319f70c175191090.png) | 
| Out[7]= |  | 
GraphicsBounds works only with 2D graphics:
| In[8]:= | ![ResourceFunction["GraphicsBounds"][
 Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]]](https://www.wolframcloud.com/obj/resourcesystem/images/32a/32a8d232-1433-4812-9052-f5c0a7f9037a/2a3074473002f537.png) | 
| Out[8]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License