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.

I have an old notebook with an output from Graphics3D, however, I've lost the data behind the output and recomputing it would take days. I simply want to remove the bounding box Mathematica usually displays unless you specify that "Boxed -> False".

Is it possible for me to still do this without having to recompute the graphic?

E.g. I want to transform an output generated from running this example command:

Graphics3D[{Sphere[{0, 0, 0}, 1], Sphere[{2, 3, 5}, 1]}]

To an example output generated from running this example command (but without having to regenerate the image since I no longer have access to the sphere coordinates):

Graphics3D[{Sphere[{0, 0, 0}, 1], Sphere[{2, 3, 5}, 1]}, Boxed -> False]
share|improve this question
    
Would it be too complicated to remove the box in Photoshop or similar? Or is it computational curiosity? –  István Zachar Mar 19 '13 at 7:51
    
@IstvánZachar I can and have solved the problem this way, but I actually have a few hundred images I'd like to do this to. And I suppose I'd like to learn something about how to do this kind of ex post facto image manipulation. There's very little info on it in the help directory. –  Roger Harris Mar 19 '13 at 7:53
    
@IstvánZachar Also, frustratingly, the line overlays my image at the desired orientation, forcing me to kind of "lie" a little while photoshopping. –  Roger Harris Mar 19 '13 at 7:58
    
Hmmmm. And I thought that you want to remove the box from an already rendered/rasterized 2D version of a Graphics3D object. That would have been much more complicated... –  István Zachar Mar 22 '13 at 13:42
add comment

3 Answers

up vote 7 down vote accepted
plt=Graphics3D[{Sphere[{0, 0, 0}, 1], Sphere[{2, 3, 5}, 1]}];
Append[plt, Boxed -> False]

Edit1:

If we have used:

 plt=Graphics3D[{Sphere[{0, 0, 0}, 1], Sphere[{2, 3, 5}, 1]}, Boxed->True]

the above codes fails. To make them more general, we can use:

 Append[DeleteCases[plt, Boxed -> _], Boxed -> False]
share|improve this answer
add comment
 g0 = Graphics3D[{Sphere[{0, 0, 0}, 1], Sphere[{2, 3, 5}, 1]}]

enter image description here

 Graphics3D[First@g0, Boxed -> False]

or, simply,

 Show[g0, Boxed -> False]

enter image description here

Alternatively, use the graphics object as input to the function

 Graphics3D[#[[1]], Boxed -> False] &

as prefix

enter image description here

or postfix

enter image description here

Update: If you have version 9, predictive interface bar includes a button to remove the bounding box:

enter image description here

share|improve this answer
    
I prefer your answer, +1 –  yulinlinyu Mar 19 '13 at 8:23
    
@kguler This is a very nice answer, thanks for taking the time to post this. –  Roger Harris Mar 19 '13 at 8:27
    
Roger, my pleasure. Just noticed that the question is edited to include Rasterize; I am afraid none of the methods suggested above work for that case :) –  kguler Mar 19 '13 at 8:44
    
@kguler Oh I didn't make the edit, but thanks! –  Roger Harris Mar 19 '13 at 8:52
    
@yulinlinyu, thanks for the vote. I think Append is really clever; never seen it used in this way. –  kguler Mar 19 '13 at 10:53
add comment

I do not feel that the existing answers adequately address this question.

First, it is important to realize the difference between aspects of a Graphics or Graphics3D object that are controlled by options and those that are not. I described this a bit here. Although you are using Graphics3D directly I mention this because objects created with a plot function will have some of their options rendered as primitives while others remain in the output and can be changed through options.

A graphics object is of the form head[primitives, options ..]. Options that appear earlier supersede those that appear later. When you have an object with explicit options it will be necessary to either replace an option value you wish to change, or simply place it earlier in the list.

gr =
 Graphics3D[
  Sphere @@@ {{}, {{1, 2, 3}}},
  Boxed -> True,
  Lighting -> {{"Directional", Orange, {{1, 0, 0}, {0, 0, 0}}}}
 ]

Mathematica graphics

It is not sufficient to Append the option Boxed -> False because there exists an earlier Boxed -> True that will override it. It is possible to use Insert:

Insert[gr, Boxed -> False, 2]

Mathematica graphics

It is also not correct to extract the first part of the object and insert it into a new Graphic3D as this will strip all options, unless of course that is your intention:

Graphics3D[First @ gr, Boxed -> False]

Mathematica graphics

You can delete a specific option as yulinlinyu shows, but it is unnecessary, and it requires that you use a more complicated method than shown if it is to be robust, because:

  • Options can be nested in lists, e.g. head[primitives, {op1, {op2, op3}}], therefore you must look deeper than level one.

  • Some options may be used inside the primitives, so you should exclude the first argument of the graphics object.

  • Options may be sub-options of another such as directives for an Epilog graphic; you would need to somehow avoid deleting these.

All in all, it's simply not worth the effort to make the delete-and-replace robust, and again, it's unnecessary. The solution is to use Show which inserts any new options at the beginning of the list automatically:

Show[gr, Boxed -> False]

Mathematica graphics

% // InputForm
Graphics3D[{Sphere[{0, 0, 0}], Sphere[{1, 2, 3}]}, {Boxed -> False, Boxed -> True, 
 Lighting -> {{"Directional", RGBColor[1, 0.5, 0], {{1, 0, 0}, {0, 0, 0}}}}}]

Use Show unless you have good reason not to.

share|improve this answer
    
Thanks, I was looking for a bit more explanation about how options for graphics work, and this really helps with that. –  Roger Harris Mar 19 '13 at 11:17
    
Simple and robust, +1 –  yulinlinyu Mar 19 '13 at 11:42
add comment

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.