# Mark an 2d-area on a 3dPlot (ListPlot3d)

I have a list {(IC,s,FK)}, which I use to generate a 3d-plot with the help of the command ListPlot3D. IC and s go from 0 to 1.

There is an area (lets say 0.11 < IC < 0.3, 0.1 < s < 0.4) which is specially important, because this is the physical range. For some reason I want to plot the whole parameter space, but highlight (for example with a red rectangle) this physical range. It would be great to frame the physical range with a red rectangle on the surface of the 3d-Plot. (In the end, this 2d-rectangle should look similar to these mesh lines, but it should frame the range, defined above).

Do you have any idea?

-
Please include a self contained example (code) of what you're trying to do. – R. M. Dec 7 '12 at 21:23
{(x,y,z)} isn't valid syntax – Sjoerd C. de Vries Dec 7 '12 at 21:33
I took as guess as to what you want and posted below. If it is not correct please use that as a reference to explain what you do want. – Mr.Wizard Dec 7 '12 at 21:49
I wouldn't try to place a 2D unfilled rectangle parallel to the xy-plane to mark the domain of interest. It would be hard to make it both visible and easy to relate to the data. I think I'd go for superimposing a sub-plot of the same data with different coloring over the domain of interest. Wish I could work this out and post it, but I don't think I'll find the time. – m_goldberg Dec 8 '12 at 0:35

## 4 Answers

With

 data = Table[{x = RandomReal[{-1, 1}], y = RandomReal[{-1, 1}], x^2 - y^2}, {300}];


Three possible methods are

1. using ColorFunction
2. using a combination of Mesh, MeshFunctions and MeshShading, (or, and better yet, just Mesh and MeshShading as in @Brett's answer)
3. produce two plots using different RegionFunction settings and combine them using Show.

Using ColorFunction:

 ListPlot3D[data, BoxRatios -> Automatic, Mesh -> None,
ColorFunction -> Function[{x, y, z}, If[-.5 < x < .5 && -.3 < y < .1, Red, White]],
ColorFunctionScaling -> False, BoxRatios -> Automatic,
MaxPlotPoints -> 100, Lighting -> "Neutral"]


or with a different setting for the ColorFunction, say:

 ColorFunction -> Function[{x, y, z}, If[-.5 < x < .5 && -.3 < y < .1,
ColorData["DeepSeaColors", (1 + x)/2], Directive[Opacity[.7], Hue[(1 + z)/2]]]]


Using Mesh, MeshFunctions and MeshShading:

 ListPlot3D[data,
MeshFunctions -> {Boole[-.5 < #1 < .5 && -.2 < #2 < .75] &},
Mesh -> {{1}},  MeshShading -> {White, Red},
BoxRatios -> Automatic,  MaxPlotPoints -> 100, Lighting -> "Neutral"]


Using RegionFunction and Show:

lp1 = ListPlot3D[data,
RegionFunction -> (! (-.5 < #1 < .5 && -.2 < #2 < .75) &),
Mesh -> None, BoxRatios -> 1,
MaxPlotPoints -> 100, Lighting -> "Neutral",
ColorFunction -> (Directive[Opacity[.9], Hue[#1]] &),
Lighting -> "Neutral",   ImageSize -> 300];
lp2 = ListPlot3D[data,
RegionFunction -> ((-.5 < #1 < .5 && -.2 < #2 < .75) &),
Mesh -> None, BoxRatios -> 1,
MaxPlotPoints -> 100, Lighting -> "Neutral",
ColorFunction -> (Red &), Lighting -> "Neutral",
ImageSize -> 300];
Panel@Row[{lp1, lp2, Show[{lp1, lp2}]}, Spacer[5]]


-
lol -- when did that answer get there? +1 – Mr.Wizard Dec 7 '12 at 22:39
@Mr.W, same here - I should learn to reload the page every 30 secs or so :) Thank you for the vote. – kglr Dec 7 '12 at 23:03
Great, thanks a lot! – Peter Dec 8 '12 at 12:14
One last question. I chose solution number one, using 'ColorFunction'. Instead of the color white, I want use my originally blue color. I tried, but could not find the correct Colordata. Do you know it by accident? Would be great! – Peter Dec 8 '12 at 14:26
@Peter, thanks for the accept. You can try using, say, Lighter@Lighter@Lighter@Blue instead of White inside If. But ... I think it is easier to use the second approach to get the Automatic settings working nicely: just change White to Automatic and remove the Lighting option (or set it to Automatic). – kglr Dec 8 '12 at 23:35

This can be done with the Mesh family of options.:

dat = Join @@
Table[{x, y, Sin[10 x y]}, {x, 0, 1, 0.05}, {y, 0, 1, 0.05}];

ListPlot3D[dat, Mesh -> {{0.11, 0.3}, {0.1, 0.4}}, MeshStyle -> None,
MeshShading -> {{Automatic, Automatic, Automatic},
{Automatic, Directive[Red, Lighting -> "Neutral"], Automatic},
{Automatic, Automatic, Automatic}}]


Since your example is in $x-y$ coordinates, we can use the default functions with specific positions, and use MeshStyle -> None to hide the lines (which we probably aren't interested in, in this case.) Then we just have to construct the appropriate setting for MeshShading.

-
Great, thanks a lot! – Peter Dec 8 '12 at 12:13

Second attempt:

dat = Join @@ Table[{x, y, Sin[10 x y]}, {x, 0, 1, 0.05}, {y, 0, 1, 0.05}];

ListPlot3D[
dat,
ColorFunctionScaling -> False,
ColorFunction -> (If[0.11 < # < 0.3 && 0.1 < #2 < 0.4, Red, Gray] &)
]


One method to clean up the fuzzy edge:

f = Interpolation[dat];

Plot3D[
f[x, y], {x, 0, 1}, {y, 0, 1},
ColorFunctionScaling -> False,
ColorFunction -> (If[0.11 < # < 0.3 && 0.1 < #2 < 0.4, Red, Gray] &),
PlotPoints -> 100
]


I seem to remember seeing a better one but I cannot recall it.

-
Thanks for your fast answer. I am looking for a 2d-area on the surface of the 3d-plot. (Similar like these mesh-lines, but only in a certain area and with another color) – Peter Dec 7 '12 at 22:23
@Peter please see my updated answer and again give feedback. – Mr.Wizard Dec 7 '12 at 22:34
Thanks a lot! Peter – Peter Dec 9 '12 at 15:07

My solution is using ListPlot3D twice:

data = Join @@
Table[{x, y, Sin[10 x y]}, {x, 0, 1, 0.05}, {y, 0, 1, 0.05}];

g1 = ListPlot3D[data];
g2 = ListPlot3D[data, Mesh -> None,
RegionFunction ->
Function[{x, y, z}, 0.11 < x < 0.3 && 0.1 < y < .4],
BoundaryStyle -> Directive[Red, Thick], PlotStyle -> None,
MaxPlotPoints -> 50]

Show[g1, g2]


-
Thanks a lot! Peter – Peter Dec 9 '12 at 15:07