Is there a simple way to omit legend entries?

조회 수: 23 (최근 30일)
Srh Fwl
Srh Fwl 2021년 6월 16일
댓글: Ioannis Matthaiou 2022년 3월 18일
I have plotted figures where there are numerous diagonal reference lines. I only need one line to appear in the legend. However, none of the solutions I have found so far online seem to work for getting rid of the unnecessary lines. The best I can do so far (as shown in my example figure) is to remove the text "Reference line" but not the associated line. Can anyone offer advice?
I have made my legend by doing this:
refline4=plot(xref4,yref4,'Color',[0.4 0.4 0.4],'LineStyle', '-','Linewidth',0.5,'DisplayName','Reference line'); hold on
Then:
lgd=legend('Location','northwest');
When I delete
DisplayName','Reference line',
I don't get the test "Reference line" for a particular line, but I do get the line as shown in my figure. Is there a way to eliminate the lines in a way that works with the code I have? I have a lot of it and it would be very onerous to have to collect the legend labels in lists (and leave the items I don't want out of the lists) as shown in another solution I saw online. Thank you.

채택된 답변

Jonas
Jonas 2021년 6월 16일
you can do your normal graph plotting and one of your reference lines and then you can set the auto update property of the legend to off. after that you can plot the other reference lines.
  댓글 수: 4
Srh Fwl
Srh Fwl 2021년 6월 17일
Thank you very much. That works--using
'AutoUpdate','off'
and then putting the plot commands that I don't want to be included in the legend after it.
Ioannis Matthaiou
Ioannis Matthaiou 2022년 3월 18일
great!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by