Thread Subject: Set legend regardless of plot

Subject: Set legend regardless of plot

From: Chris

Date: 9 Dec, 2008 15:00:19

Message: 1 of 4

Hi,
I'm having trouble setting my legend correctly. I have 3 sets of data plotted in a for loop which plot mulitple lines each. I want a single line in the legend with a corresponding colour not an entry for each line.

The line my books and searches on the internet have suggested is:
legend('-b','Ganymede','-g','Callisto','-k','Europa');

but this displays six legend entrys - all of the same colour as the first 6 lines calculated in the loop. Hopefully I'm missing something silly!

Cheers,
Chris

Subject: Set legend regardless of plot

From: Srikanth

Date: 9 Dec, 2008 16:39:34

Message: 2 of 4

On Dec 9, 8:00=A0am, "Chris " <chris.craws...@gmail.com> wrote:
> Hi,
> I'm having trouble setting my legend correctly. I have 3 sets of data plo=
tted in a for loop which plot mulitple lines each. I want a single line in =
the legend with a corresponding colour not an entry for each line.
>
> The line my books and searches on the internet have suggested is:
> legend('-b','Ganymede','-g','Callisto','-k','Europa');
>
> but this displays six legend entrys - all of the same colour as the first=
 6 lines calculated in the loop. Hopefully I'm missing something silly!
>
> Cheers,
> Chris

Try getting a handle for the line(s) you want a legend(s) for - if
there are more than one, just store them in a array and then use those
handles to display your legend

Subject: Set legend regardless of plot

From: Chris

Date: 9 Dec, 2008 19:48:03

Message: 3 of 4

Srikanth <skt@xdtech.com> wrote in message <bd617f21-3b2b-44f3-bc82-c49d76775871@f40g2000pri.googlegroups.com>...
> On Dec 9, 8:00=A0am, "Chris " <chris.craws...@gmail.com> wrote:
> > Hi,
> > I'm having trouble setting my legend correctly. I have 3 sets of data plo=
> tted in a for loop which plot mulitple lines each. I want a single line in =
> the legend with a corresponding colour not an entry for each line.
> >
> > The line my books and searches on the internet have suggested is:
> > legend('-b','Ganymede','-g','Callisto','-k','Europa');
> >
> > but this displays six legend entrys - all of the same colour as the first=
> 6 lines calculated in the loop. Hopefully I'm missing something silly!
> >
> > Cheers,
> > Chris
>
> Try getting a handle for the line(s) you want a legend(s) for - if
> there are more than one, just store them in a array and then use those
> handles to display your legend

I'm sorry, I don't understand that - do you mean create a name for each line on the graph and select lines 1, 11, 21 to be on the legend?

Here is part of the script - is there somewhere I can load up the whole thing, or is it okay to paste it here?

col=['b';'g';'k'];
for i=1:3
    for Vinf=Vmin:5e2:Vmax; %V_infinity (m/s)
figure(1);
plot(rP,P,col(i));
legend('-b','Ganymede','-g','Callisto','-k','Europa');
hold on;
end
end
hold off

Subject: Set legend regardless of plot

From: Johan Carlson

Date: 10 Dec, 2008 06:35:02

Message: 4 of 4

Srikanth <skt@xdtech.com> wrote in message <bd617f21-3b2b-44f3-bc82-c49d76775871@f40g2000pri.googlegroups.com>...
> On Dec 9, 8:00=A0am, "Chris " <chris.craws...@gmail.com> wrote:
> > Hi,
> > I'm having trouble setting my legend correctly. I have 3 sets of data plo=
> tted in a for loop which plot mulitple lines each. I want a single line in =
> the legend with a corresponding colour not an entry for each line.
> >
> > The line my books and searches on the internet have suggested is:
> > legend('-b','Ganymede','-g','Callisto','-k','Europa');
> >
> > but this displays six legend entrys - all of the same colour as the first=
> 6 lines calculated in the loop. Hopefully I'm missing something silly!
> >
> > Cheers,
> > Chris
>
> Try getting a handle for the line(s) you want a legend(s) for - if
> there are more than one, just store them in a array and then use those
> handles to display your legend

You might be able to use this function (legendlinestyles)
http://www.mathworks.com/matlabcentral/fileexchange/22116

/JC

Tags for this Thread

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.

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