Legend inside a plot

조회 수: 9 (최근 30일)
Ocram
Ocram 2012년 5월 27일
Hi all, I want to plot more than two graphs inside a figure, but I would like to label with a legend just two of them. It is possible without writing anything in the related position inside the command legend: legend('string1','','','string2')
but I get the line of the missing label in the legend panel!!
How can I take off the string and the symbol in the legend panel???
Thanks M
  댓글 수: 2
Oleg Komarov
Oleg Komarov 2012년 5월 27일
You can start by giving a complete example of the issue:
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Ocram
Ocram 2012년 5월 27일
y1= sin(1:1:20)
y2= 3*sin(1:1:20)
y3= 2*sin(1:1:20)+3
plot(y1,'r'), hold on,
plot(y2,'b:'), hold on,
plot(y3,'g'),
legend('y1','','y3')
I tried to plot 3 tracks but I can't cancel the second line in the legend. I didn't write the name of this second string, but the line remains.

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

답변 (2개)

Walter Roberson
Walter Roberson 2012년 5월 27일

Ocram
Ocram 2012년 5월 27일
I tried this second code:
y1= sin(1:1:20)
y2= 3*sin(1:1:20)
y3= 2*sin(1:1:20)+3
plot(y1,'r'), hold on,
h= plot(y2,'b:'), hold on,
plot(y3,'g'),
set(get(get(h,'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend
legend('y1','y3')
but in this case I have direct access to the single plot commands.
Instead, I have a function which return me just the figure with different tracks inside.... so I can't get the handle like in this last example.
  댓글 수: 3
Ocram
Ocram 2012년 5월 28일
It doesn't work out. :(
Oleg Komarov
Oleg Komarov 2012년 5월 28일
What do you mean? It does work for me:
axch = get(gca, 'Children');
set(get(get(axch(2),'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by