0
$\begingroup$

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"}]
$\endgroup$
1
  • $\begingroup$ The option's name is PlotLegends $\endgroup$ Mar 24, 2015 at 19:15

1 Answer 1

4
$\begingroup$

You have a typo in the syntax:

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

You forgot 's' in PlotLegends.

$\endgroup$
8
  • $\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, 2015 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, 2015 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$ Mar 24, 2015 at 17:56
  • $\begingroup$ In your case it works. In my case it doesn't work. $\endgroup$
    – Lorenzo
    Mar 24, 2015 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$ Mar 24, 2015 at 18:09

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