Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
1  
You can check out this answer by @Jens to a question of mine several months ago for cropping 3D graphics. –  Guillochon Mar 11 '13 at 7:16
1  
Borderline duplicate: Export Graphics without white edges –  Yves Klett Mar 11 '13 at 7:53

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
3  
I'm glad to see that has been added to the documentation. +1 –  Mr.Wizard Mar 11 '13 at 8: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 8:26
    
@Mr.Wizard, just added my e-mail to my profile (was confused about public visibility of the e-mail address in the profile:) –  kguler Mar 11 '13 at 8: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 2:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.