Function Repository Resource:

EnlargeBoundingBox

Source Notebook

Increase a bounding box by a fractional amount

Contributed by: Taliesin Beynon (Wolfram Research)

ResourceFunction["EnlargeBoundingBox"][{{l,r},{b,t}},frac]

enlarges the given bounding box by the fraction frac of its width and height.

ResourceFunction["EnlargeBoundingBox"][{{l,r},{b,t}},{{dl,dr},{db,dt}}]

enlarges the given bounding box by the given amount on each side.

Details and Options

A zero fraction gives the graphics with a {{l,r},{b,t}} bounding box.

Examples

Basic Examples (3) 

Basic usage:

In[1]:=
ResourceFunction["EnlargeBoundingBox"][{{0.1, .2}, {.3, .4}}, 1/2]
Out[1]=

Feed in Graphics objects:

In[2]:=
Graphics[{Disk[]}, PlotRange -> ResourceFunction["EnlargeBoundingBox"][{{-1, 1}, {-1, 1}}, 1/3]]
Out[2]=

Adjust each side, increasing the extent as we go from left to right and then bottom to top:

In[3]:=
ResourceFunction[
 "EnlargeBoundingBox"][{{-1, 1}, {-1, 1}}, {{.2, .4}, {.6, .8}}]
Out[3]=
In[4]:=
Graphics[{Disk[]}, PlotRange -> %, Frame -> True]
Out[4]=

Scope (1) 

EnlargeBoundingBox also works on 3D graphics:

In[5]:=
Graphics3D[{Sphere[]}, PlotRange -> ResourceFunction["EnlargeBoundingBox"][{{-1, 1}, {-1, 1}, {-1, 1}}, 2]]
Out[5]=

Applications (1) 

Create a zoom effect:

In[6]:=
Manipulate[
 Graphics3D[{Sphere[], Cuboid[]}, PlotRange -> ResourceFunction[
    "EnlargeBoundingBox"][{{-1, 1}, {-1, 1}, {-1, 1}}, r]], {r, 2, 0}]
Out[6]=

Publisher

Enrique Zeleny

Version History

  • 1.0.0 – 29 June 2020

License Information