9

If the option Boxed is set to be False in Graphics3D, additional white margins may appear as shown in the following figure. Is it possible to remove the useless margins such that the borders touch the contents?

smallarray = 
 With[{L0 = 300, r0 = 50, unitcellsize = 400, origin = {0, 0, 0}, 
   la = 800, ra = 50 },
  Graphics3D[{EdgeForm[None], Yellow, 
    Table[{Cylinder[{{ix*unitcellsize, iy*unitcellsize - L0/2, 
         0}, {ix*unitcellsize, iy*unitcellsize + L0/2, 0}}, r0]}, {ix,
       1, 5}, {iy, 1, 5}], Arrowheads[0.1], Red, 
    Arrow[Tube[{origin, origin + {la, 0, 0}}, ra]], Magenta, 
    Arrow[Tube[{{0, 0, 0}, origin + {0, la, 0}}, ra]], Cyan, 
    Arrow[Tube[{origin, origin + {0, 0, la}}, ra]]}, Boxed -> False, 
   Lighting -> Automatic, ViewPoint -> {Pi, Pi/2, Pi}, 
   ImageSize -> {Automatic, 400}]]

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Tony Dong
  • 869
  • 9
  • 16

1 Answers1

15

The option you need is Method->{"ShrinkWrap"->True}. From the Documentation Center Graphics3D>Options>Method:

By default, empty space may appear around a graphical image ..
Use Method->{"ShrinkWrap"->True} to prevent the inclusion of empty space.

smallarray = 
 With[{L0 = 300, r0 = 50, unitcellsize = 400, origin = {0, 0, 0},  la = 800, ra = 50}, 
 Graphics3D[{EdgeForm[None], Yellow, 
 Table[{Cylinder[{{ix*unitcellsize, iy*unitcellsize - L0/2, 
     0}, {ix*unitcellsize, iy*unitcellsize + L0/2, 0}}, r0]},
  {ix,  1, 5}, {iy, 1, 5}], Arrowheads[0.1], Red, 
 Arrow[Tube[{origin, origin + {la, 0, 0}}, ra]], Magenta, 
 Arrow[Tube[{{0, 0, 0}, origin + {0, la, 0}}, ra]], Cyan, 
 Arrow[Tube[{origin, origin + {0, 0, la}}, ra]]}, Boxed -> False, 
 Lighting -> Automatic, ViewPoint -> {Pi, Pi/2, Pi}, 
 ImageSize -> {Automatic, 400}, PlotRangePadding -> 0, 
 ImagePadding -> 0, Method -> {"ShrinkWrap" -> True}]]

enter image description here enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
  • 3
    I'm glad to see that has been added to the documentation. +1 – Mr.Wizard Mar 11 '13 at 08:25
  • By the way, I see that your avatar is changing with your IP address again. Why did you remove the email from your profile? – Mr.Wizard Mar 11 '13 at 08:26
  • @Mr.Wizard, just added my e-mail to my profile (was confused about public visibility of the e-mail address in the profile:) – kglr Mar 11 '13 at 08:52
  • @kguler The email and real name fields are not publicly visible. You can check what is visible publicly by viewing your profile using an incognito session in Chrome (or its equivalent in FF/Safari/Opera/IE) – rm -rf Mar 11 '13 at 19:03
  • If I add some text into the figure such as Table[Text[Style[ix, 24, Bold], {ix*unitcellsize, 0, 0}], {ix, 1, 5}] and use Method -> {"ShrinkWrap" -> True}, the number 5 won't appear. What happened in this case? – Tony Dong Mar 14 '13 at 02:39
  • 2
    @kglr: You MUST work for WRI... you simply know too damn much! So very helpful. (+1) – David G. Stork Apr 16 '19 at 03:52