How can I add a patch which lies underneath an existing line?
Afficher commentaires plus anciens
If I have a plot containing a line, I would like to add a patch but have it appear under the line so the line remains visible. (Not possible to plot the patch first in my real application). How can I do this using the example below?
figure;
h = plot(rand(1,10), rand(1,10)); % Make a line plot
hold on;
% Get coordinates for a patch in the lower quarter of the figure
xd = get(gca, 'xlim'); xd = [xd(1) xd(2)/2];
yd = get(gca, 'ylim'); yd = [yd(1) yd(2)/2];
x = [xd(1) xd(2) xd(2) xd(1) xd(1)];
y = [yd(1) yd(1) yd(2) yd(2) yd(1)];
% The following patch lies over the line
p = patch(x, y, 'g');
1 commentaire
CS Researcher
le 3 Mai 2016
You can change the coordinates of the patch.
Réponse acceptée
Plus de réponses (1)
Robert
le 3 Mai 2016
You can reorder the Children property of the axes on which you have drawn you line and patch. For example, in my application I use a variation on the following:
ax = gca;
set(ax,'Children',circshift(get(ax,'Children'),1))
If you have only the two children, your code would be as effective and more readable if you simply use
set(gca,'Children',[h,p])
Catégories
En savoir plus sur Polygons 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!