Azzera filtri
Azzera filtri

hiding legend in plot

469 visualizzazioni (ultimi 30 giorni)
Sayanta
Sayanta il 30 Nov 2012
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

Risposta accettata

Honglei Chen
Honglei Chen il 4 Dic 2012
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})

Più risposte (2)

Sean de Wolski
Sean de Wolski il 4 Dic 2012
Get the handle form the legend when you create it
hLeg = legend('example')
Then turn its visibility off
set(hLeg,'visible','off')
  1 Commento
Nirjhar Kumar
Nirjhar Kumar il 1 Apr 2019
Modificato: Nirjhar Kumar il 1 Apr 2019
in case you dont have the any handle:
hFig=findall(0,'type','figure');
hLeg=findobj(hFig(1,1),'type','legend');
set(hLeg,'visible','off')

Accedi per commentare.


Sayanta
Sayanta il 5 Dic 2012
Thanks Honglei, Your code works perfectly
  2 Commenti
Payam Nia
Payam Nia il 24 Set 2015
b = gca; legend(b,'off');
Marco A. Acevedo Z.
Marco A. Acevedo Z. il 8 Mag 2023
thanks Payam.

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by