Please consider this simple code:

 Plot[{a Sin[x], a Cos[x]}, {x, 0, 2 Pi}, 
  PlotLegends -> "Expressions"], {a, 1, 2}]

Mathematica returns this output:

enter image description here

I believe this is a bug. Is there any workaround to cope with this problem?

I use Mathematica version 10.3.1 on Win 10 64bit. Thank you.


The FrontEnd has the habit of renaming variables, which is usually a good thing, but sometimes can be troublesome. One possibility is to evaluate the argument of Plot, e.g.:

       Plot @@ {{a Sin[x], a Cos[x]}, 
                {x, 0, 2 Pi},
                 PlotLegends -> "Expressions", 
                 PlotRange -> {-2, 2}}, {4, 3}
    {a, 1., 2, Appearance -> "Labeled"}]

enter image description here

  • $\begingroup$ The usage of Appearance is first time to me.I'm interested that how do you know it?? $\endgroup$ – yode Jan 20 '16 at 19:22

Legends are heavily affecting the performance in Dynamic so I'd probably go with some hand made legends anyway:

    Dynamic @ Plot[{a Sin[x], a Cos[x]}, {x, 0, 2 Pi}]
     {RGBColor[0.368417, 0.506779, 0.709798], RGBColor[0.880722, 0.611041, 0.142051]},
     TraditionalForm /@ {Dynamic[a Defer@Sin[x]], Dynamic[a Defer@Cos[x]]}
    }}], {a, 1, 2}]

enter image description here

Colors for lines taken from Match colors to plot themes

  • 2
    $\begingroup$ Why not simply Manipulate[ Plot[{a Sin[x], a Cos[x]}, {x, 0, 2 Pi}, PlotLegends -> {Dynamic[a Sin[x]], Dynamic[a Cos[x]]}], {a, 1, 2}]. I got same result. $\endgroup$ – Basheer Algohi Jan 21 '16 at 1:34
  • $\begingroup$ @Algohi I don't know how fast your machine is but on mine there is a noticable difference. The face that the Plot has to use PlotLegends slows it down a lot. $\endgroup$ – Kuba Jan 21 '16 at 7:19

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.