# How do I plot a line delineating a subset of values on a 3D surface plot?

I have the following surface plot:

Plot3D[-4.53 + 2.67*x + 2.78*y - 1.09*x*y, {x, 1.8, 2.6}, {y, 1.8, 2.6},
PlotRange -> {1.7, 2.6}, ColorFunction -> "GrayTones",
Ticks -> {{1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}},
LabelStyle -> Opacity[0], BoxRatios -> {1, 1, 1}]


There is no problem with this plot. What I now want to do is to superimpose some line(s) or ellipse(s) on its surface that delineate(s) all values on the surface in which z (the function) is between the corresponding x and y values, that is, all values for which x < z < y OR y < z < x.

I imagine that the resulting line or lines may extend from one edge of the surface to another or there may be a couple of ellipses. Despite my efforts, I have been unable to mentally visualize the actual result, only possible results like those I mention above.

Finally, I have almost no expertise at Mathematica. The above surface plot took me weeks to figure out, and most of that was through trial and error, not any sort of knowledge of the language or syntax of Mathematica.

Follow-up: I also wish to delineate where x is between z and y. I came up with:

Plot3D[-4.53 + 2.67 x + 2.78 y - 1.09 x y, {x, 1.8, 2.6}, {y, 1.8, 2.6}, PlotRange -> {1.7, 2.6}, Ticks -> {{1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}}, LabelStyle -> Opacity[0], BoxRatios -> Automatic, MeshFunctions -> {Function[{x, y, z}, z - x], Function[{x, y, z}, z - y], Function[{x, y, z}, x - y], Function[{x, y, z}, x - z]}, Mesh -> {{0}, {0}, {0}, {0}}, MeshShading -> None, Lighting -> "Neutral"]

The problem is that either there is no portion where y < x < z, or I am incorrectly specifying this. Also, I cannot for the life of me figure out how to do MeshShading to shade each of the regions. Thank you in advance.

• Take a look at MeshFunctions. – Kuba Nov 26 '14 at 16:14
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Nov 26 '14 at 16:21

The region where $z$ is between $x$ and $y$ is bounded by the curves $z = x$ and $z = y$, or equivalently, $z-x=0$ and $z-y=0$. To draw these curves in the plot, the usual trick is to supply the left-hand sides of the equations to MeshFunctions and specify that Mesh lines be drawn only when they are zero.

Plot3D[-4.53 + 2.67 x + 2.78 y - 1.09 x y, {x, 1.8, 2.6}, {y, 1.8, 2.6},
PlotRange -> {1.7, 2.6},
Ticks -> {{1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}},
LabelStyle -> Opacity[0], BoxRatios -> Automatic,
MeshFunctions -> {Function[{x, y, z}, z - x], Function[{x, y, z}, z - y]},
Mesh -> {{0}, {0}}, MeshShading -> {{White, Pink}, {Pink, White}}, Lighting -> "Neutral"]


I've also used MeshShading to highlight in pink the region where the first function is positive and the second is negative, or vice versa, which is the same as the region you seek.

Also note that, for example, Function[{x, y, z}, z - x] can also be written as #3 - #1 &, which is the syntax in which you'll often find examples written in the MeshFunctions documentation.

• Raul, this is perfect. Thank you so much. This is exactly what I was looking for -- more, in fact, with the nice choice of the pink shading. Thanks again. – kwsockman Nov 26 '14 at 18:46
• I'm glad to hear it. You can accept the answer by clicking the checkbox to the left if you want to indicate that it solves your problem. – Rahul Nov 27 '14 at 7:28
• Thanks again, Raul and Kuba. Initially, I thought that the answer to my question above would get me started on figuring out for myself what I also need to do. But I have not succeeded, so I am posting here another question. – kwsockman Nov 28 '14 at 13:56