Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Why can't I add plots to axes after creating a legend?

조회 수: 2 (최근 30일)
Avishek  Mondal
Avishek Mondal 2017년 7월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
I was following the instructions here https://uk.mathworks.com/help/matlab/ref/legend.html. However, when I run the following code (is the same as one provided in the link) -
x = linspace(0,10);
y1 = sin(x);
plot(x,y1)
legend('First Line')
hold on
y2 = cos(x);
plot(x,y2,'DisplayName','Second Line')
I get the attached graph. Could someone please tell me why this is happening? Thank you!

답변 (1개)

Image Analyst
Image Analyst 2017년 7월 8일
legend() does not automatically update when you add stuff. How could it know what you want to call the additional curves? I don't know what the 'DisplayName' option is in plot(). My R2017a help for plot does not mention that as a possible option. Is that what you thought legend() would automatically use? Evidently not. You'll have to call legend after you're all done plotting curves, not before then.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by