MATLAB Answers

Figure legend: how to prevent entries from showing?

조회 수: 11(최근 30일)
Xiaohan Du
Xiaohan Du 22 Feb 2018
Hi all,
My code plots a figure with a few curves, after the code finishes running, I manually add the legend like this:
legend('original', '', '', 'proposed', '', '', 'Proposed with optimisation')
So my figure looks like:
I do not need these extra lines after the 'original' and 'proposed', how can I remove the 2, 3, 5, 6th entries? Or how can I add the legend without these? i.e. a legend with only 3 entries?
Many thanks!

  댓글 수: 0

로그인 to comment.

답변 수 (1)

Are Mjaavatten
Are Mjaavatten 22 Feb 2018
Are Mjaavatten 님이 편집함. 22 Feb 2018
h = plot(....);
legend(h([1,4,7]),'original','proposed','proposed with optimisation')

  댓글 수: 2

Xiaohan Du
Xiaohan Du 22 Feb 2018
Hi Are,
The problem is I add the legend manually after the code finishes running, so I don't have
h = plot(...);
and I cannot use
h([1, 4, 7])
Any idea how to use [1 4 7] without defining h?
Are Mjaavatten
Are Mjaavatten 25 Feb 2018
With your plot (or rather: axes) in focus, try:
h = get(gca,'children')
Most likely, the lines are in the correct order, but you may have to experiment a little. Typing h(1) will show details like linestyle and marker of this line.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by