# Choosing which edges of the box to show in 3D graphics

Is there a way to explicitly choose which edges of the bounding box to show when plotting something with Boxed->True?

For instance, a plot like

Plot3D[Sin[Pi*x]*Sin[2 Pi*y], {x, 0, 1}, {y, 0, 1}]


returns the image and I would like to remove the three edges of the box which go over the plot, but keep all others.

How can this be done? The documentation does not seem to mention any option which would allow it.

Update: The undocumented Mathematica setting

Boxed -> {Back, Bottom, Left}


is the easiest solution. See my answer below.

• Does this question help? Apr 22, 2015 at 19:24
• @Virgil It is a possible solution, but the end result is pretty ugly. I've edited in an example use of FaceGrids.
– sps
Apr 22, 2015 at 20:57

I am answering my own question as I have discovered an undocumented Mathematica feature which does exactly what I wanted.

While playing around with some plot options, I discovered that setting

PlotTheme->"Monochrome"


had precisely the effect that I wanted - it displayed only some of the edges of the box. So I started digging, and running

ChartingResolvePlotTheme["Monochrome", Plot3D]


I noticed something surprising in the options for the theme... namely the setting:

Boxed -> {Back, Bottom, Left}


This is the kind of intuitive and easy solution that I would have expected Mathematica to have from the beginning, but it doesn't seem to be mentioned anywhere in the documentation.

Example of what it does:

 Plot3D[Sin[Pi*x]*Sin[2 Pi*y], {x, 0, 1}, {y, 0, 1}, Boxed -> {Back, Bottom, Left}] I hope this helps someone else with this problem!

• Fantastic discovery! Apr 27, 2015 at 22:03

If you use Mathematica 10:

plotrange = {{0, 1}, {0, 1}, {-1, 1}};
edges = Composition[
Part[#, {8, 7, 4, 6, 2, 10, 9, 5, 1, 3, 11, 12}] &,
Delete[#, List /@ {1, 5, 6, 9, 11, 15}] &,
MeshPrimitives[#, 1] &,
BoundaryDiscretizeRegion,
Apply[Cuboid],
Transpose
][plotrange];
Show[
Plot3D[
Sin[Pi*x]*Sin[2 Pi*y],
{x, 0, 1},
{y, 0, 1},
Axes -> True,
AxesLabel -> {x, y, z},
Boxed -> False,
BoxRatios -> {2, 2, 1},
PlotRange -> plotrange
],
Graphics3D[{
Gray,
edges[[{3, 4, 7, 8, 11, 12}]]
}]
] Edges indices have been set as follows: • Fantastic! This works perfectly.
– sps
Apr 26, 2015 at 9:39

Well, if you don't want to use FaceGrids (which can be pretty ugly), you could construct the box you want by hand:

With[{xi = 0, xf = 1, yi = 0, yf = 1, zmin = -1, zmax = 1},
Show[Plot3D[Sin[Pi*x]*Sin[2 Pi*y], {x, xi, xf}, {y, yi, yf}, Boxed -> False],
Graphics3D[{
GrayLevel[0.75], Line[1.02{
{xi, yi, zmin},
{xi, yf, zmin},
{xf, yf, zmin},
{xf, yf, zmax},
{xi, yf, zmax},
{xi, yf, zmin},
{xi, yf, zmax},
{xi, yi, zmax},
{xi, yi, zmin}}]}, Boxed -> False],
PlotRange -> {{xi, xf}, {yi, yf}, {zmin, zmax}}]
]
` Doing this does require knowledge of the range the z-coordinate will take.