# ListPlot3D with contours projected onto the xy-plane

I am relatively new to Mathematica and have a question regarding ListPlot3D.

I am plotting results for the 2 dimensional heat equation for a particular point in time, so to each (x,y) in my partition of the xy-plane (with x ranging from 0 to 100, y from 0 to 200), there is point in the z direction that represents the heat as a function of x and y (and time, but the plot represents the heat distribution at a fixed point in time). This was done using the finite difference method.

I initially plotted the results using ListPointPlot3D as well as ListPlot3D (which of course "interpolates" the points). I would like to plot some level curves on the xy-plane, but in absence of z as closed-form function of x and y, I do not know how to do this with Mathematica.

Essentially, what I would like to do is intersect the ListPlot3D surface with a few planes of constant height above the xy-plane, and then project the intersections on to the xy-plane, but because I do not have an explicit function to which I can equate the plane equation to, I have to find an alternative method. Does anyone have any suggestions on this?

Alternatively, is there another feature in Mathematica of which I am unaware that will compute a best-fit function, so I can supply a number of tuples of the form {x, y, z(x,y)} and get a closed-form solution of z?

Any help would be greatly appreciated.

• Try the option MeshFunctions -> {#3 &} in ListPlot3D[]. Look up ListContourPlot[] as well. – J. M.'s technical difficulties Mar 25 '18 at 20:12
• The ListContourPlot feature works quite well, actually. Thanks. I appreciate it. – mrmingus Mar 25 '18 at 20:51

You could use SliceContourPlot3D, e.g.

With[{f = Sin[x] Cos[y]},
Show[Plot3D[f, {x, -3, 3}, {y, -3, 3}, Mesh -> None,
PlotStyle -> Opacity[0.3]
], SliceContourPlot3D[
f - z - 1, {z == -1}, {x, -3, 3}, {y, -3, 3}, {z, -1, 10},
PlotLegends -> Automatic]]]


I have been using this simple low-level trick to create slices:

1. First, you generate separately a 3D plot and whatever 2D plot you are interested in. If I understand your discrete problem correctly, you could do this step by extracting the relevant sublists from the data (see the online doc for Select[] if you are wondering how to do it).
2. Next, you convert your 2D Graphic into a 3D Graphic by converting each pair of points {x,y} into a triplet {x,y,z}. For a horizontal slice, I simply use z=offset but you could use any function f:{x,y}->{x’,y’,z’}.
3. Use Show to combine both 3D graphics.

Here is an example of the code:

f[x_, y_] = x^2 + y^2;
offset = -2;
landscape = Plot3D[f[x, y], {x, -1, 1}, {y, -1, 1},
PlotStyle -> Opacity[0.7],
ColorFunction -> "Rainbow"];
map = ContourPlot[f[x, y], {x, -1, 1}, {y, -1, 1}];
map3D = Graphics3D[map[[1]] /. {x : _Real, y : _Real} -> {x, y, offset}];
Show[landscape, map3D,
PlotRange -> {Automatic, Automatic, {offset, 2}}
]


• Elegant and beautiful, can be applied in other situations as well. Thanks – Laryx Decidua Mar 19 at 15:33