How to make contourf plots beyond a polygon invisible?

8 views (last 30 days)
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

John D'Errico
John D'Errico on 17 Jan 2014
Use patch to overlay white on top.
  1 Comment
Leon
Leon on 17 Jan 2014
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

Find more on Contour Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!