what is the best way of showing legend?

조회 수: 2 (최근 30일)
Ham Man
Ham Man 2022년 8월 17일
댓글: Ham Man 2022년 8월 18일
could anyone tell me what is the best way of showing legend in this example?
plot(x1,y1,'o-r',-x1,y1,'o-r');hold on;
plot(x2,y2);
%I tried this way:
legend('show');legend('plotx1y1','','plotx2y2');
% but it does not look good!
I appreciate any help!

채택된 답변

dpb
dpb 2022년 8월 17일
You don't explain what you don't like nor show us what you got and we don't have your data, so we're flying blind here, but I'll guess
plot([-x1(:);x1(:)],[y1(:);y1(:)],'o-r');
hold on;
plot(x2,y2);
legend('plotx1y1','plotx2y2');
or
hL=gobjects(3,1); % preallocate for line handles to come
hL=plot(x1,y1,'o-r',-x1,y1,'o-r'); % first two
hold on;
hL(3)=plot(x2,y2); % and third...
legend(hL([1 3]),'plotx1y1','plotx2y2'); % label the desired ones
or
plot(x1,y1,'o-r','DisplayName','plotx1y1','Annotation','on'); % first, use legend
hold on;
plot(-x1,y1,'o-r','Annotation','off'); % no legend on second
plot(x2,y2,'DisplayName','plotx2y2','Annotation','on'); % show third
legend % turn the legend on
  댓글 수: 1
Ham Man
Ham Man 2022년 8월 18일
Many thanks, I used the first suggested method and it works fine!

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

추가 답변 (0개)

카테고리

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