Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Inconsistent behavior of RegionFunction in ContourPlot and ListContourPlot
Replies: 0

 Alexey Posts: 266 Registered: 6/14/08
Inconsistent behavior of RegionFunction in ContourPlot and ListContourPlot
Posted: Aug 18, 2012 3:44 AM

Hello folks,

When trying to plot a non-covex set of datapoints ListContourPlot produces a
convex graph effectively extrapolating values outside of the actual range of
the original dataset:

pts = {{1, 1, 1}, {2, 1.2, .8}, {3, 1.3, .7}, {3, 2, 1}, {1.5, 2,
1}, {1.5, 1.5, 1}};
epilog = {FaceForm[None], EdgeForm[Red], Polygon[Most /@ pts]};
ListContourPlot[pts, Epilog -> epilog]

(the red polygon shows the actual range of the data).

I need to remove the extrapolated parts of the graph and define
RegionFunction:

leftBorder =
Interpolation[pts[[{5, 6, 1}, {2, 1}]], InterpolationOrder -> 1];
bottomBorder =
Interpolation[pts[[{1, 2, 3}, {1, 2}]], InterpolationOrder -> 1];
ListContourPlot[pts, Epilog -> epilog,
RegionFunction ->
Function[{x, y, z},
x >= leftBorder[y] && y >= bottomBorder[x]]]

But as you see, nothing happens! The drawn region of the plot still contains
areas outside of the area allowed by the RegionFunction.

There is no such problem with ContourPlot:

ContourPlot[Sin[x y], {x, 1, 3}, {y, 1, 2}, Epilog -> epilog,
RegionFunction ->
Function[{x, y, z}, x >= leftBorder[y] && y >= bottomBorder[x]]]

Is it a bug in ListContourPlot? How to achieve consistent behavior of
RegionFunction in both ContourPlot and ListContourPlot?