# Adding walls to a region plot

I've done this code:

Plot3D[x + y + 1, {x, 0, 1}, {y, 0, 1},
RegionFunction -> Function[{x, y, z}, 0 <= y <= Sqrt[x]]]


Producing this image:

In MATLAB, I used the mesh command:

u=linspace(0,1,40);
v=linspace(0,1,40);
[u,v]=meshgrid(u,v);
x=u;
y=v.*sqrt(u);
z=x+y+1;
h=meshz(x,y,z);
Z=get(h,'Zdata');
Z([1 end],:)=0;
Z(:,[1,end])=0;
set(h,'ZData',Z)
xlabel('x-axis')
ylabel('y-axis')


To produce this image:

Is there a Mathematica function that will add the walls to my first image?

• Filling -> Bottom?
– Kuba
Nov 6, 2014 at 17:22
• B´gosh, but that Matlab plot is hard on the eyes! @Kuba that deserves an answer! Nov 6, 2014 at 17:44
• UnderstatementQ["hard on the eyes"] (*True*)
– gpap
Nov 6, 2014 at 17:47

While I like gpap's solution, it requires quite a bit of work. So, instead, use the built-in options. The important one is FaceGrids which takes a list of vectors which specify which side the grid is on.

Plot3D[x + y + 1, {x, 0, 1}, {y, 0, 1},
RegionFunction -> Function[{x, y, z}, 0 <= y <= Sqrt[x]],
FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, Boxed -> False,
Filling -> Bottom, FillingStyle -> Green, ColorFunction -> Hue]


• Aaaaaargh, facegrids dammit. I faintly remember using this at some point but it's not exactly common. +1 this is far better than mine!
– gpap
Nov 6, 2014 at 18:24
• @rollyer: How can you make the fill drop to the xy-plane (at z=0 instead of at z=1). Nov 7, 2014 at 2:28
• @David yes, add the option PlotRange -> {0, Automatic} to it. Nov 7, 2014 at 2:43
• Absolutely what I needed for my students. Thank you so much. Nov 7, 2014 at 4:58

It will be easy to write a function that operates on the plot and takes the minimum value of each coordinate and adds a plane to combine the plots. I really don't have time to do this for you now so I've just copy-pasted some planes and changed the options to match the (uglier in my opinion) plotting style of MATLAB:

Show[{
ParametricPlot3D[{0, y, z}, {y, 0, 1}, {z, 1, 3},
PlotStyle -> White, Lighting -> "Neutral"],
ParametricPlot3D[{x, 1, z}, {x, 0, 1}, {z, 1, 3},
PlotStyle -> White, Lighting -> "Neutral"],
ParametricPlot3D[{x, y, 1}, {x, 0, 1}, {y, 0, 1},
PlotStyle -> White, Lighting -> "Neutral"],
Plot3D[{x + y + 1}, {x, 0, 1}, {y, 0, 1},
RegionFunction -> Function[{x, y, z}, 0 <= y <= Sqrt[x]],
Mesh -> 90, Filling -> Bottom, ColorFunction -> Hue,
FillingStyle -> Directive[Darker@Green, Opacity[1]]]},
PlotRange -> {{0, 1}, {0, 1}, {1, 3}}, BoxRatios -> {2, 2, 1},
Boxed -> False, Background -> LightGray]


As I said, I can automate this but it'll have to wait until later/tomorrow if the above isn't satisfactory.