Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am having trouble with adding a legend to a plot. The example I discuss here is simpler than my real problem, but describes it well.

I have a vector, called X with dimensions (100 x 6). I use the command ListPlot to plot one row of X at a time:

plotX={};
Do[
p1=ListPlot[X[[i]]];
AppendTo[plotX,p1],
{i,1,Length[X]}];

Therefore, the list plotX contains six list plots with 100 points each. To show all the plots, I use the command Show

Show[plotX]

Now I want to create a legend for this graph, for example {"x1","x2","x3","x4","x5","x6"}. How can I do this?

Thanks

share|improve this question
    
If you have version 9 you can use the PlotLegends option. –  b.gatessucks Dec 12 '12 at 16:59
    
@b.gatessucks - Unfortunately I have version 7, however PlotLegends work in version 7 too, in fact sometimes I used it, but in this case I can't to resolve the problem with that command –  Emanuele Dec 12 '12 at 17:06
    
It would help if you add to the question information about what happens when you try to use PlotLegends in your version. –  David Z Dec 12 '12 at 17:14
    
@DavidZaslavsky - Simple problem like: Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, PlotLegend -> {"sine", "cosine"}] I have no problem, but in my example gives me error and a message: An unr"ecognized option name ("PlotLegends`PlotLegend") was encountered while reading a GraphicsBox." –  Emanuele Dec 12 '12 at 17:35
    
@Emanuele as I said, it helps if you add the information to the question, that way it is properly visible. –  David Z Dec 12 '12 at 17:45
show 2 more comments

1 Answer

I would plot all the data sets you have in one go :

$Version
(* "7.0 for Linux x86 (64-bit) (February 18, 2009)" *)

data = Table[Sin[i] + j, {i, 1, 100}, {j, 1, 6}];

Needs["PlotLegends`"]

ListPlot[Transpose[data], Joined -> True,  
     PlotLegend -> {"x1", "x2", "x3", "x4", "x5", "x6"}]

plot

share|improve this answer
    
I have to plot a list of point not a function therefore I can't do the graph in this way. –  Emanuele Dec 12 '12 at 19:12
1  
I am not plotting a function, I used Sin just to make up some data. Have a look at my data or post yours and I'll update my answer. –  b.gatessucks Dec 12 '12 at 19:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.