I am trying to add a legend to a plot, but sometimes it work and sometimes it doesn't work and I don't understand why. For example, when I use the following code, I get as an error "Unknown option PlotLegend".

Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, PlotLegend -> {"sine", "cosine"}]
  • $\begingroup$ The option's name is PlotLegends $\endgroup$ – Dr. belisarius Mar 24 '15 at 19:15

You have a typo in the syntax:

Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, PlotLegends -> {"sine", "cosine"}]

You forgot 's' in PlotLegends.

| improve this answer | |
  • $\begingroup$ I get the same error both with PlotLegend and PlotLegends. The command PlotLegend exists as well. reference.wolfram.com/language/PlotLegends/ref/PlotLegend.html $\endgroup$ – Lorenzo Mar 24 '15 at 17:35
  • $\begingroup$ The point is that with the same code yesterday it was working. Might it be a problem with libraries? $\endgroup$ – Lorenzo Mar 24 '15 at 17:37
  • $\begingroup$ flic.kr/p/rJJRTh You can see window of my Matematica with difference between PlotLegend and PlotLegends. And on the site, which you gave above, write about Needs["PlotLegends`"] and there're red highlighted misspelling flic.kr/p/rM2Mwp $\endgroup$ – Roman Alexeev Mar 24 '15 at 17:56
  • $\begingroup$ In your case it works. In my case it doesn't work. $\endgroup$ – Lorenzo Mar 24 '15 at 18:01
  • 1
    $\begingroup$ reference.wolfram.com/language/PlotLegends/tutorial/… I suppose we use different versions of Mathematica. Try to add this instruction before use Plot: << PlotLegends` $\endgroup$ – Roman Alexeev Mar 24 '15 at 18:09

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