With
data = Table[{x = RandomReal[{-1, 1}], y = RandomReal[{-1, 1}], x^2 - y^2}, {300}];
Three possible methods are
- using
ColorFunction
- using a combination of
Mesh
, MeshFunctions
and MeshShading
, (or, and better yet, just Mesh
and MeshShading
as in @Brett's answer)
- 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]]