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

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
line Sebastian Gatzka 19 Jan, 2009 15:10:05
plot Sebastian Gatzka 19 Jan, 2009 15:10:05
legend Sebastian Gatzka 19 Jan, 2009 15:10:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com