How to make contourf plots beyond a polygon invisible?

I use the below to plot a contourf of a geographic region (imagine it is the Mediterranean Sea).
[X, Y] = meshgrid(linspace(min(lon),max(lon),100),linspace(min(lat),max(lat),100));
Z = griddata (lon, lat, variable, X, Y);
[C, h] = contourf (X, Y, Z, [1:0.1:4], 'LineStyle', 'none' );
The problem is that the contour extends beyond the sea into the land. How do I hide the contourf portions that extend beyond the boundary (polygon)? Thanks.

 Accepted Answer

Use patch to overlay white on top.

1 Comment

Thank you! So I can also use "fill"?
Is there something like inpolygon, so that I can crop the part that I want?

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 17 Jan 2014

Commented:

on 17 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!