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:


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


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


  • $\begingroup$ If you have version 9 you can use the PlotLegends option. $\endgroup$ Dec 12, 2012 at 16:59
  • $\begingroup$ @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 $\endgroup$
    – Emanuele
    Dec 12, 2012 at 17:06
  • $\begingroup$ It would help if you add to the question information about what happens when you try to use PlotLegends in your version. $\endgroup$
    – David Z
    Dec 12, 2012 at 17:14
  • $\begingroup$ @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." $\endgroup$
    – Emanuele
    Dec 12, 2012 at 17:35
  • $\begingroup$ @Emanuele as I said, it helps if you add the information to the question, that way it is properly visible. $\endgroup$
    – David Z
    Dec 12, 2012 at 17:45

1 Answer 1


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

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

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


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


  • $\begingroup$ I have to plot a list of point not a function therefore I can't do the graph in this way. $\endgroup$
    – Emanuele
    Dec 12, 2012 at 19:12
  • 1
    $\begingroup$ 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. $\endgroup$ Dec 12, 2012 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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