Got Questions? Get Answers.
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

Thread Subject:
Exclude line from plot ledgend

Subject: Exclude line from plot ledgend

From: Sebastian Gatzka

Date: 19 Jan, 2009 20:07:02

Message: 1 of 4

Hello World.

I have added a line object to my plot, which is displayed in the legend now.
I have read, that I can suppress the output inside the legend, but havent found a way of doing it by now.
What is the right syntax for it?

Thanks in advance. S.

Subject: Exclude line from plot ledgend

From: Sadik

Date: 20 Jan, 2009 00:15:05

Message: 2 of 4

"Sebastian Gatzka" <sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote in message <gl2mh5$fkt$1@fred.mathworks.com>...
> Hello World.
>
> I have added a line object to my plot, which is displayed in the legend now.
> I have read, that I can suppress the output inside the legend, but havent found a way of doing it by now.
> What is the right syntax for it?
>
> Thanks in advance. S.

Hello Sebastian,

To do that, you need the handle to the legend.

So, let us say you have 4 such lines plotted on top of each other, and you say:

legendHandle = legend('line1','line2','line3','line4');

then, you would like to suppress line4. What you should do is

legend(legendHandle,'line1','line2','line3')

Hope this helps.

Subject: Exclude line from plot ledgend

From: Sebastian Gatzka

Date: 20 Jan, 2009 18:06:01

Message: 3 of 4

Thats it!
Thank you!

Subject: Exclude line from plot ledgend

From: Pekka Kumpulainen

Date: 21 Jan, 2009 08:31:02

Message: 4 of 4

"Sebastian Gatzka" <sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote in message <gl53q9$ir5$1@fred.mathworks.com>...
> Thats it!
> Thank you!

That works if you want to drop the last one. It will only change the labels but keeps the linestyles and colors of the first 3 lines.
You can use the line handles to control which you want in the legend.
Say you have an array hl containing the line handles (hl = plot(mydata))
then legend(hl([1 3 4]),'Line1','Line3','Line4') will use the right lines in the legend.
If you need to tweak then a lot it might be easier to set the DisplayName property of the line objects and you don't need to type the texts in each call to legend.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us