Fill the plot but it should not be closed by connecting first vertex to the last
Afficher commentaires plus anciens
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.
Réponses (1)
Walter Roberson
le 10 Oct 2015
0 votes
There are two ways to handle fill in MATLAB:
- 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.
- 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 commentaires
PRITESH GARG
le 10 Oct 2015
Modifié(e) : PRITESH GARG
le 10 Oct 2015
Walter Roberson
le 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');
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
