12
$\begingroup$

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]
$\endgroup$
4
  • $\begingroup$ Would it be too complicated to remove the box in Photoshop or similar? Or is it computational curiosity? $\endgroup$ Commented Mar 19, 2013 at 7:51
  • $\begingroup$ @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. $\endgroup$ Commented Mar 19, 2013 at 7:53
  • $\begingroup$ @IstvánZachar Also, frustratingly, the line overlays my image at the desired orientation, forcing me to kind of "lie" a little while photoshopping. $\endgroup$ Commented Mar 19, 2013 at 7:58
  • $\begingroup$ 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... $\endgroup$ Commented Mar 22, 2013 at 13:42

3 Answers 3

7
$\begingroup$
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]
$\endgroup$
8
$\begingroup$
 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

$\endgroup$
5
  • $\begingroup$ I prefer your answer, +1 $\endgroup$
    – yulinlinyu
    Commented Mar 19, 2013 at 8:23
  • $\begingroup$ @kguler This is a very nice answer, thanks for taking the time to post this. $\endgroup$ Commented Mar 19, 2013 at 8:27
  • $\begingroup$ 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 :) $\endgroup$
    – kglr
    Commented Mar 19, 2013 at 8:44
  • $\begingroup$ @kguler Oh I didn't make the edit, but thanks! $\endgroup$ Commented Mar 19, 2013 at 8:52
  • $\begingroup$ @yulinlinyu, thanks for the vote. I think Append is really clever; never seen it used in this way. $\endgroup$
    – kglr
    Commented Mar 19, 2013 at 10:53
6
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Thanks, I was looking for a bit more explanation about how options for graphics work, and this really helps with that. $\endgroup$ Commented Mar 19, 2013 at 11:17
  • $\begingroup$ Simple and robust, +1 $\endgroup$
    – yulinlinyu
    Commented Mar 19, 2013 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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