Adding legend to plots created by for loops

조회 수: 1 (최근 30일)
mr mo
mr mo 2017년 12월 4일
편집: mr mo 2017년 12월 4일
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
how can l manage my legend ? thank you

답변 (1개)

KL
KL 2017년 12월 4일
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');
  댓글 수: 1
mr mo
mr mo 2017년 12월 4일
편집: mr mo 2017년 12월 4일
Actually I am ploting my dataset by this function https://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube and I don't know how to add legend to this function. Thanks a lot.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by