Thread Subject: Bypass a Line Plotted in the Legend

Subject: Bypass a Line Plotted in the Legend

From: Dima

Date: 4 Feb, 2012 14:44:28

Message: 1 of 7

Hello!)

I wonder how do I bypass a line plot out of multiple plots when putting the legend on a chart.

Suppose I have 10 vectors plotted on a chart. If I wish to make the legend display the info for only the first 3 time series and only for the last one...how do I do that?

leg = legend('one','two','three','four','five','six','seven','eight','nine','ten','Location','SouthEast');

Thanks!

Dima

Subject: Bypass a Line Plotted in the Legend

From: Bjorn Gustavsson

Date: 4 Feb, 2012 17:19:19

Message: 2 of 7

"Dima " <dima_chernovolov@yahoo.com> wrote in message <jgjg8c$omh$1@newscl01ah.mathworks.com>...
> Hello!)
>
> I wonder how do I bypass a line plot out of multiple plots when putting the legend on a chart.
>
> Suppose I have 10 vectors plotted on a chart. If I wish to make the legend display the info for only the first 3 time series and only for the last one...how do I do that?
>
> leg = legend('one','two','three','four','five','six','seven','eight','nine','ten','Location','SouthEast');
>
> Thanks!
>
> DimaIf you call plot with an output argument:

ph = plot(randn(10));

You can select which lines to have in the legend:

legend(ph([1:3,end]),'1','2,'3','432')

HTH

Subject: Bypass a Line Plotted in the Legend

From: Dima

Date: 4 Feb, 2012 17:49:15

Message: 3 of 7

"Bjorn Gustavsson" <bjonr@irf.se> wrote in message <jgjpan$k4k$1@newscl01ah.mathworks.com>...
> "Dima " <dima_chernovolov@yahoo.com> wrote in message <jgjg8c$omh$1@newscl01ah.mathworks.com>...
> > Hello!)
> >
> > I wonder how do I bypass a line plot out of multiple plots when putting the legend on a chart.
> >
> > Suppose I have 10 vectors plotted on a chart. If I wish to make the legend display the info for only the first 3 time series and only for the last one...how do I do that?
> >
> > leg = legend('one','two','three','four','five','six','seven','eight','nine','ten','Location','SouthEast');
> >
> > Thanks!
> >
> > DimaIf you call plot with an output argument:
>
> ph = plot(randn(10));
>
> You can select which lines to have in the legend:
>
> legend(ph([1:3,end]),'1','2,'3','432')
>
> HTH

THANKS!!! But what if I have a chart full of the various plot lies and markers and I need only to have some of these in the legend and those lines are all not plotted with one plot command....do you think it is possible??
thanks!)

Subject: Bypass a Line Plotted in the Legend

From: dpb

Date: 4 Feb, 2012 18:20:38

Message: 4 of 7

On 2/4/2012 11:49 AM, Dima wrote:
...

> THANKS!!! But what if I have a chart full of the various plot lies and
> markers and I need only to have some of these in the legend and those
> lines are all not plotted with one plot command....do you think it is
> possible??
> thanks!)

Possible, sure...

You may have to do things like get() the properties of the lines in
question and set() the legend properties to match but if you save the
optional object handles from the legend call(s), you can modify the
properties at will or even add more lines, etc., etc., to the legend.
It (a legend, that is) is simply an axis object w/ lines, text, et al.

doc legend

--

Subject: Bypass a Line Plotted in the Legend

From: Abioye Samson

Date: 4 Feb, 2012 18:48:24

Message: 5 of 7

u can decide to use an empty strings where u don't want to label the line using legend.
e.g
legend('one','two','three','','','','','','last')

Subject: Bypass a Line Plotted in the Legend

From: dpb

Date: 4 Feb, 2012 19:12:19

Message: 6 of 7

On 2/4/2012 12:48 PM, Abioye Samson wrote:
> u can decide to use an empty strings where u don't want to label the
> line using legend.
> e.g
> legend('one','two','three','','','','','','last')

Certainly, but if the plot was created w/ multiple calls to plot, it's
possible (probable?) the line styles aren't going to be in synch
automagically...

--

Subject: Bypass a Line Plotted in the Legend

From: Steven_Lord

Date: 6 Feb, 2012 14:45:59

Message: 7 of 7



"Dima " <dima_chernovolov@yahoo.com> wrote in message
news:jgjr2r$ou0$1@newscl01ah.mathworks.com...
> "Bjorn Gustavsson" <bjonr@irf.se> wrote in message
> <jgjpan$k4k$1@newscl01ah.mathworks.com>...
>> "Dima " <dima_chernovolov@yahoo.com> wrote in message
>> <jgjg8c$omh$1@newscl01ah.mathworks.com>...
>> > Hello!)
>> >
>> > I wonder how do I bypass a line plot out of multiple plots when putting
>> > the legend on a chart.
>> >
>> > Suppose I have 10 vectors plotted on a chart. If I wish to make the
>> > legend display the info for only the first 3 time series and only for
>> > the last one...how do I do that?
>> >
>> > leg =
>> > legend('one','two','three','four','five','six','seven','eight','nine','ten','Location','SouthEast');
>> >
>> > Thanks!
>> >
>> > DimaIf you call plot with an output argument:
>>
>> ph = plot(randn(10));
>>
>> You can select which lines to have in the legend:
>>
>> legend(ph([1:3,end]),'1','2,'3','432')
>>
>> HTH
>
> THANKS!!! But what if I have a chart full of the various plot lies and
> markers and I need only to have some of these in the legend and those
> lines are all not plotted with one plot command....do you think it is
> possible??

Sure, as long as you keep track of your handles.


mylines = zeros(1, 5);
x = 0:0.1:2*pi;
axis([0 2*pi -1 1]);
hold on
listOfMarkers = {'o', 'x', '.', 's', 'd'};
listOfColors = 'rgbyc';
for k = 1:5
    mylines(k) = plot(x, sin(k*x), ...
        [listOfMarkers{k} '-'], ... % get the right marker and line style
        'Color', listOfColors(k)); % get the right color
end
legend(mylines([1 3 5]), 'sin(x)', 'sin(3*x)', 'sin(5*x)');


--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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

Contact us at files@mathworks.com