5
$\begingroup$

I would like to find an easy way to show parts of the bounding box as solid planes. Given this Plot: current 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. enter image description here

$\endgroup$

3 Answers 3

2
$\begingroup$

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]

enter image description here

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

enter image description here

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"]

enter image description here

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

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ plot /. GrayLevel[x_, y_] :> GrayLevel[0.5, .5] $\endgroup$
    – cvgmt
    Feb 3, 2021 at 23:26
4
$\begingroup$
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]

enter image description here

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

enter image description here

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]

enter image description here

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – Tino
    Feb 3, 2021 at 12:52
  • $\begingroup$ @Tino, you are right about white gridlines. The only way i can think of to get white gridlines is to add the line primitives. $\endgroup$
    – kglr
    Feb 3, 2021 at 13:17
  • $\begingroup$ ... or have a non-white background. $\endgroup$
    – kglr
    Feb 3, 2021 at 13:24
  • $\begingroup$ @Tino, please see the other answer I posted to get white gridlines. $\endgroup$
    – kglr
    Feb 3, 2021 at 21:24

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.