How can I cover up areas of a plot?

3 views (last 30 days)
John
John on 28 Mar 2014
Commented: Image Analyst on 28 Mar 2014
Basically I'm plotting contours on a grid, but I want to cover part of the plot area up.
The contours are defined on a grid with x and y vectors:
contour(x,y,C)
I want to be able to cover sections of the plot with a filled area determined by whether a grid point is included in the area or not. So for example, for the given points on an 8x6 grid:
mask = [1 1 1 1 0 0 0 0
1 1 1 1 0 0 1 1
0 0 0 0 0 0 1 1
0 0 0 0 1 0 0 0
0 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0];
I want to superimpose my contour plot with a rectangle, a square, and a triangle, at the corresponding positions in the grid. Does anybody have any idea how to go about doing this? I'm at a complete loss. I still need the underlying contour plot to be visible at those points marked '0', I just want to fill in the squares/triangles on the grid bounded by '1's.
I can plot the points that bound the areas just with
plot(x,meshgrid(x,y).*mask)
but I want to fill in the areas in between, not just have points.

Answers (1)

Image Analyst
Image Analyst on 28 Mar 2014
Try patch() or fill().
  2 Comments
John
John on 28 Mar 2014
Hi,
I had a look in the help but I'm really not sure how I'd go about converting the mask I have into something useful for either of those functions. Could be you a bit more specific?
Image Analyst
Image Analyst on 28 Mar 2014
Well you have to get the vertex coordinates. Alternatively you could follow Steve's suggestion: http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/

Sign in to comment.

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!