Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

hiding legend in plot

Asked by Sayanta

Sayanta (view profile)

on 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

0 Comments

Sayanta

Sayanta (view profile)

Tags

Products

3 Answers

Answer by Honglei Chen

Honglei Chen (view profile)

on 4 Dec 2012
Accepted answer

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})

0 Comments

Honglei Chen

Honglei Chen (view profile)

Answer by Sean de Wolski

Sean de Wolski (view profile)

on 4 Dec 2012

Get the handle form the legend when you create it

hLeg = legend('example')

Then turn its visibility off

set(hLeg,'visible','off')

0 Comments

Sean de Wolski

Sean de Wolski (view profile)

Answer by Sayanta

Sayanta (view profile)

on 5 Dec 2012

Thanks Honglei, Your code works perfectly

0 Comments

Sayanta

Sayanta (view profile)

Contact us