Adding legend to plots created by for loops
1 view (last 30 days)
Show older comments
l want to make a legend for my figure that was created by 3 for loops like mentioned below :
legend 1 : essential
legend 2 : less essential
legend 3 : most important
for P=1:K
% body
plot(.....,'bo');
end
for Z=N:T
%body
plot(....,'ro'):
end
for i=1:L
%body
plot(....,'ko'):
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170602/image.jpeg)
how can l manage my legend ? thank you
0 Comments
Answers (1)
KL
on 4 Dec 2017
There are various ways. You can simply add the legend after you plot everything like,
legend({'essential','less essential','most important'})
or
you can add it while plotting inside the loop like
for P=1:K
% body
plot(.....,'bo',,'DisplayName','essential');
end
%other loops
and finally,
lgd = legend('show');
See Also
Categories
Find more on Legend 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!