# Issue using RegionFunction with ListContourPlot

I've hit a problem using RegionFunction with ListContourPlot and am hoping someone can help.

I'm trying to use RegionFunction with ListContourPlot to suppress the rendering of contours outside a prescribed polygon.

The first example in this notebook works as I'd expect. The second does not, in that the contours are drawn outside the specified polygon.

Any suggestions/advice would be much appreciated.

• Crossposted here. Mar 21 at 15:47

First, precompute RegionMemberFunction for better performance. Second, increase MaxPlotPoints.

regMem = RegionMember[Polygon[...]];

Show[ListContourPlot[...,
RegionFunction -> Function[{x, y, z}, regMem[{x, y}]],
MaxPlotPoints -> 50]
]


Alternatively, if you don't want all of your points to get additionally resampled at a grid (which is what increasing MaxPlotPoints does and can be observed with Mesh -> All), you can trick Mathematica by providing RegionFunction of a region which is very slightly smaller than your actual region of datapoints. This will trigger finer resampling only at the boundary (observe with mesh). I do not know whether this can also be achieved in any other way ...

reg = Polygon[...];
smallerReg =
GeometricTransformation[reg,
ScalingTransform[{1 - 1/100000, 1 - 1/100000}, RegionCentroid[reg]]];
regMem = RegionMember[smallerReg];

Show[ListContourPlot[...,
RegionFunction -> Function[{x, y, z}, regMem[{x, y}]]
]


• A bit of a follow-up question...
– Ian
Mar 21 at 12:59
• ...what exactly does the optional argument MaxPlotPoints do when used with ListContourPlot? The documentation says "ListContourPlot normally uses all of the points in the dataset". In which case, I'm not sure why increasing the value from the default "All" would make the difference it does.
– Ian
Mar 21 at 13:04
• ...is it a case of "decreasing" the value of MaxPlotPoints rather than "increasing" it?
– Ian
Mar 21 at 13:05
• OK, I think I've figured it out. Looks like ListContourPlot resamples the data on a square grid with the number of grid points being defined by MaxPlotPoints.
– Ian
Mar 21 at 13:22
• @Ian, please also see my update for another possible method. Mar 21 at 16:24

The resolution of the "ListContourPlot" is too small. Add e.g.: "MaxPlotPoints->30"