Fill the plot but it should not be closed by connecting first vertex to the last

6 views (last 30 days)
I have a plot which consists of alternate layers of two species. I need to fill these layers with specified colors but it should not be closed by connecting last vertex to the first. When I use the fill command it connects the vertices and I do not want it that way. Please guide.

Answers (1)

Walter Roberson
Walter Roberson on 10 Oct 2015
There are two ways to handle fill in MATLAB:
  1. use patch() or surface() or one of the derived functions fill() or contourf() to create a closed bounded object which has a face which is coloured with the desired fill colour.
  2. convert some or all of the axes content into an image in which you have painted the desired fill colour and carefully place the image on the axes.
I would wonder if the issue is not that you do not want the polygon to be closed, but rather that you do not want the edge to be drawn? An example of what you want would help.
  2 Comments
PRITESH GARG
PRITESH GARG on 10 Oct 2015
Edited: PRITESH GARG on 10 Oct 2015
As shown in the figure, I need to fill in the area between the layers. I have arrays for the curves shown by red and black lines. Area under the black and above red should be Black and the one under the red and above black should be Red.
Walter Roberson
Walter Roberson on 10 Oct 2015
You would normally proceed by constructing closed boundaries with the first connected to the last. It just might not be the boundaries you thought of at first.
Presuming that the X values are all the same, and letting the red and black lines be columns in Y, then, to fill between columns K and K+1 you would construct
fx = [X(:); flipud(X(:))];
fy = [Y(:,K); flipud(Y(end,K+1))];
col = [0 0 0] or [1 0 0] or as appropriate
fill(fx, fy, col, 'edgecolor', 'none');

Sign in to comment.

Categories

Find more on Graphics Object Properties 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!