hiding legend in plot

조회 수: 386 (최근 30일)
Sayanta
Sayanta 2012년 11월 30일
댓글: Marco A. Acevedo Z. 2023년 5월 8일
Dear All,
I want to hide one legend from my graph. Could you please suggest a procedure or steps to do it.
Here is the code below to hiding my legend but doesn't work.
legend(h4,'off')
legend(h4,'toggle')
legend('h1','h2', 'h3', 'h4','h5');
Many Thanks in advance
Babai

채택된 답변

Honglei Chen
Honglei Chen 2012년 12월 4일
I assume you have 5 handles, h1 through h5, but want to hide h4 from appearing in a legend. If that's the case, since you know all handles, the easiest way is probably
legend([h1 h2 h3 h5],{'h1','h2','h3','h5})

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 12월 4일
Get the handle form the legend when you create it
hLeg = legend('example')
Then turn its visibility off
set(hLeg,'visible','off')
  댓글 수: 1
Nirjhar Kumar
Nirjhar Kumar 2019년 4월 1일
편집: Nirjhar Kumar 2019년 4월 1일
in case you dont have the any handle:
hFig=findall(0,'type','figure');
hLeg=findobj(hFig(1,1),'type','legend');
set(hLeg,'visible','off')

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


Sayanta
Sayanta 2012년 12월 5일
Thanks Honglei, Your code works perfectly
  댓글 수: 2
Payam Nia
Payam Nia 2015년 9월 24일
b = gca; legend(b,'off');
Marco A. Acevedo Z.
Marco A. Acevedo Z. 2023년 5월 8일
thanks Payam.

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

카테고리

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