# Filling FaceGrids of Plot3D, with solid color?

I would like to find an easy way to show parts of the bounding box as solid planes. Given this Plot:

plot = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
ColorFunction -> "BlueGreenYellow",
FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, Boxed -> False]


I would like the bounding box to be displayd like this: If possible, keep the planes of the bounding box behind the plot dynamically.

We can use SliceContourPlot3D with "BackPlanes" as the slice surface to add face grids with desired colors:

ClearAll[addFaceGrids]
addFaceGrids[color_: GrayLevel[.8], linecolor_: White] := Module[{r = PlotRange[#]},
Show[#, SliceContourPlot3D[#, "BackPlanes",
{x, r[[1, 1]], r[[1, 2]]}, {y, r[[2, 1]], r[[2, 2]]}, {z, r[[3, 1]], r[[3, 2]]},
ContourShading -> {color, color}, Contours -> {Automatic, 6},
ContourStyle -> Directive[Thick, linecolor],
BoundaryStyle -> Directive[Thick, linecolor]] & /@ {x, y, z}]] &


Examples:

addFaceGrids[] @ Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
ColorFunction -> "BlueGreenYellow", Boxed -> False]


addFaceGrids[Opacity[.1, Red]] @
Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
ColorFunction -> "BlueGreenYellow", Boxed -> False,  BoxRatios -> {3, 2, 1}]


addFaceGrids[Opacity[.1, LightBlue]] @
ParametricPlot3D[{Cos[3 u], Sin[5 u], u/2}, {u, 0, 2 Pi},
PlotStyle -> {Red, Tube[.02]}, ImageSize -> Medium,
Boxed -> False,  Lighting -> "Neutral"]


• Thank you! This works ! <3
– Tino
Commented Feb 5, 2021 at 11:21
plot = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
ColorFunction -> "BlueGreenYellow",
PlotTheme -> {"Marketing", "NoAxes"}, Boxed -> False]


• plot /. GrayLevel[x_, y_] :> GrayLevel[0.5, .5] Commented Feb 3, 2021 at 23:26
ClearAll[canvas]
canvas[color_: GrayLevel[0, .3]] := Graphics3D@{{EdgeForm[], color, EdgeForm[None],
InfinitePlane[{Scaled[{0, 0, 0}], Scaled[{0, 1, 0}], Scaled[{1, 1, 0}]}],
InfinitePlane[{Scaled[{0, 0, 0}], Scaled[{0, 0, 1}], Scaled[{0, 1, 1}]}],
InfinitePlane[{Scaled[{0, 1, 0}], Scaled[{0, 1, 1}], Scaled[{1, 1, 1}]} ]}}

plot = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
ColorFunction -> "BlueGreenYellow",
FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, Boxed -> False];

Show[plot, canvas[], PlotRange -> All]


Show[plot, canvas[Opacity[.3, Orange]], PlotRange -> All]


plot2 = Plot3D[x + Sin[x/2 + (y/2)^2], {x, 4, 6}, {y, 7, 9},
ColorFunction -> "BlueGreenYellow",
FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}},
Boxed -> False, BoxRatios -> {3, 2, 1}];

Show[plot2, canvas[Opacity[.2, Blue]], PlotRange -> All]


• This a nice idea, unfortunatly it has some disadvantages, for example if one was to change the FaceGridStyle to white, it show that the planes are covering the Grindlines.
– Tino
Commented Feb 3, 2021 at 12:52
• @Tino, you are right about white gridlines. The only way i can think of to get white gridlines is to add the line primitives.
– kglr
Commented Feb 3, 2021 at 13:17
• ... or have a non-white background.
– kglr
Commented Feb 3, 2021 at 13:24
• @Tino, please see the other answer I posted to get white gridlines.
– kglr
Commented Feb 3, 2021 at 21:24