How can I plot legends on only some of my curves that all plotted together?

I am using ListPlot to plot many lines in the same graph. I want to put in a legend but only for a subset of these lines. For example

ListPlot[{P1,P2,P3,P4},PlotLegend -> {“a”,”b”}]

where P1,P2,P3,P4 are some lists that one can plot, however this creates a legend for -all- plots P1,…,P4, with empty texts for some of them. How can I make a legend that only lables two of the lines?

=================

  

 

Perhaps Show[{ListPlot[{P1,P2}, PlotLegend->{“a”, “b”}], ListPlot[{P3,P4}]}] including PlotRange if needed.
– Bill
Oct 28 ’15 at 1:21

  

 

You mean PlotLegends, not PlotLegend.
– Verbeia♦
Oct 28 ’15 at 1:27

3

 

@Verbeia: He may really be using the old PlotLegends package — it had the syntax and behavior described.
– Brett Champion
Oct 28 ’15 at 2:14

=================

1 Answer
1

=================

Works for me

{p1, p2, p3, p4} =
Accumulate /@ RandomVariate[NormalDistribution[0, 1], {4, 50}];

ListLinePlot[{p1, p2, p3, p4}, PlotLegends -> {“a”, “b”}]

What version of Mathematica are you using?

ListPlot works fine, though of course by default you get dots not an unbroken line.

1

 

Same result for v9
– Dr. belisarius
Oct 28 ’15 at 1:51

  

 

Actually I was using PlotLegend, which gives the behaviour I described (and no error message). With PlotLegends it works fine now.
– jon
Oct 28 ’15 at 16:02

  

 

But what is the syntax if he only wanted to label, for example, P1 and P4? Without using the Show function..
– niq
Oct 10 at 17:10