# Mesh generation for a discrete set of points in ListContourPlot?

Given a (possibly disjoint) region, defined by a discrete set of points, how can I use ListContourPlot[] together with Mesh to highlight a specific area of the plot? For instance, how can I mesh the region where the points are smaller than a certain value?

Here I construct a minimal example where I try to highlight the area where the values of a discrete sample of the function $$f(x) = e^{x^2 - y^2}$$ are smaller then one.

data = Table[Exp[x^2 - y^2], {x, -1, 1, .01}, {y, -1, 1, .01}];

ListContourPlot[
data
, Contours -> {1.0}
, ContourStyle -> Transparent
, Mesh -> 25
, MeshFunctions -> {#1 + #2 &}
, MeshStyle -> Thick
]


I also tried using MeshFunctions -> {Piecewise[{{#1 + #2 &, #3 <= 1 &}, {None, #3 > 0 &}}]}, but I had no luck.

I am aware that this can be done for symbolic functions through RegionPlot[], however I am not sure how to extend this to numerical data.

• MeshFunctions -> {( # + #2) Boole[#3 <= 1] &}?
– kglr
Mar 21 at 23:21
• @kglr this works perfectly, thank you! Mar 21 at 23:55
• data = Table[Exp[x^2 - y^2], {x, -1, 1, .01}, {y, -1, 1, .01}]; ListContourPlot[data, Contours -> {1.0}, ContourStyle -> Transparent, Mesh -> 25, MeshFunctions -> {Function[{x, y, f}, If[f > 1, x + y, 0]], Function[{x, y, f}, If[f < 1, x - y, 0]]}, MeshStyle -> {Red, Directive[Thick, Green]}] Mar 22 at 1:17
• @cvgmt this also works perfectly. Thank you everyone for the excellent replies! Mar 22 at 2:22

data = Table[Exp[x^2 - y^2], {x, -1, 1, .01}, {y, -1, 1, .01}];

ListContourPlot[data, Contours -> {1.0}, ContourStyle -> Transparent,
ContourShading -> {Directive[Orange, HatchFilling[-Pi/4, 1, 10]],
Directive[Cyan, HatchFilling[Pi/4, 1, 8]]}]


data = Table[Exp[x^2 - y^2], {x, -1, 1, .01}, {y, -1, 1, .01}];

Show[
ListContourPlot[data,
Contours -> {1},
Mesh -> 25,
MeshFunctions -> {#1 + #2 &},
MeshStyle -> Directive[Thick, #[[1]]],
RegionFunction -> #[[2]]] & /@
{{Red,
Function[{x, y, f}, f < 1]},
{Black, Function[{x, y, f}, f > 1]}}]


Excellent replies as usual by @cvgmt and @Bob Hanlon, but I'd like to give it a go using Piecewise

With

data = Table[Exp[x^2 - y^2], {x, -1, 1, .01}, {y, -1, 1, .01}];


The following works nicely I think

ListContourPlot[data,
Contours -> {1.0},
ContourStyle -> Transparent,
Mesh -> 25,
MeshFunctions -> {Piecewise[{{#1 + #2, #3 <= 1}}] &,
Piecewise[{{None, #1 + #2 >= 1}}] &},
MeshStyle -> Thick]