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:
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

No tags are associated with 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