Figure legend: how to prevent entries from showing?

조회 수: 123 (최근 30일)
Xiaohan Du
Xiaohan Du 2018년 2월 22일
편집: Karel Van Wambeke 2021년 5월 24일
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!

답변 (2개)

Gulam Dastagir Khan
Gulam Dastagir Khan 2020년 10월 7일
If the figure is already plotted, then do the following
  1. Select the line which you want to make invisible in legend.
  2. Then select the arrow icon from the top, this will open the property inspector.
  3. Scroll down in the property inspector dailouge box.
  4. click parent/child item
  5. In the handle visibility salect the off option.
Your line will not be appeaar in the legend now.

Are Mjaavatten
Are Mjaavatten 2018년 2월 22일
편집: Are Mjaavatten 2018년 2월 22일
h = plot(....);
legend(h([1,4,7]),'original','proposed','proposed with optimisation')
  댓글 수: 3
Are Mjaavatten
Are Mjaavatten 2018년 2월 25일
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.
Karel Van Wambeke
Karel Van Wambeke 2021년 5월 24일
편집: Karel Van Wambeke 2021년 5월 24일

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

카테고리

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