How do I plot a line delineating a subset of values on a 3D surface plot? - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-08-18T01:59:25Z https://mathematica.stackexchange.com/feeds/question/66647 http://www.creativecommons.org/licenses/by-sa/3.0/rdf https://mathematica.stackexchange.com/q/66647 3 How do I plot a line delineating a subset of values on a 3D surface plot? kwsockman https://mathematica.stackexchange.com/users/22545 2014-11-26T16:10:45Z 2014-11-28T14:34:58Z <p>I have the following surface plot:</p> <pre><code>Plot3D[-4.53 + 2.67*x + 2.78*y - 1.09*x*y, {x, 1.8, 2.6}, {y, 1.8, 2.6}, PlotRange -&gt; {1.7, 2.6}, ColorFunction -&gt; "GrayTones", Ticks -&gt; {{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 -&gt; Opacity, BoxRatios -&gt; {1, 1, 1}] </code></pre> <p>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 &lt; z &lt; y OR y &lt; z &lt; x.</p> <p>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.</p> <p>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.</p> <p>Follow-up: I also wish to delineate where x is between z and y. I came up with:</p> <p>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, 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"]</p> <p>The problem is that either there is no portion where y &lt; x &lt; 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.</p> https://mathematica.stackexchange.com/questions/66647/how-do-i-plot-a-line-delineating-a-subset-of-values-on-a-3d-surface-plot/66663#66663 3 Answer by Rahul for How do I plot a line delineating a subset of values on a 3D surface plot? Rahul https://mathematica.stackexchange.com/users/484 2014-11-26T17:46:17Z 2014-11-26T17:46:17Z <p>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 <code>MeshFunctions</code> and specify that <code>Mesh</code> lines be drawn only when they are zero.</p> <pre><code>Plot3D[-4.53 + 2.67 x + 2.78 y - 1.09 x y, {x, 1.8, 2.6}, {y, 1.8, 2.6}, PlotRange -&gt; {1.7, 2.6}, Ticks -&gt; {{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 -&gt; Opacity, BoxRatios -&gt; Automatic, MeshFunctions -&gt; {Function[{x, y, z}, z - x], Function[{x, y, z}, z - y]}, Mesh -&gt; {{0}, {0}}, MeshShading -&gt; {{White, Pink}, {Pink, White}}, Lighting -&gt; "Neutral"] </code></pre> <p><img src="https://i.stack.imgur.com/B056k.png" alt="enter image description here"></p> <p>I've also used <code>MeshShading</code> 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.</p> <p>Also note that, for example, <code>Function[{x, y, z}, z - x]</code> can also be written as <code>#3 - #1 &amp;</code>, which is the syntax in which you'll often find examples written in the <code>MeshFunctions</code> documentation.</p>