# Problem with PlotLegends in Manipulate

Please consider this simple code:

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


Mathematica returns this output: 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.

## 2 Answers

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.:

Manipulate[
NumberForm[
Plot @@ {{a Sin[x], a Cos[x]},
{x, 0, 2 Pi},
PlotLegends -> "Expressions",
PlotRange -> {-2, 2}}, {4, 3}
],
{a, 1., 2, Appearance -> "Labeled"}] • The usage of Appearance is first time to me.I'm interested that how do you know it?? – 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:

Manipulate[
Grid[{{
Dynamic @ Plot[{a Sin[x], a Cos[x]}, {x, 0, 2 Pi}]
,
LineLegend[
{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}] Colors for lines taken from Match colors to plot themes

• 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. – Basheer Algohi Jan 21 '16 at 1:34
• @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. – Kuba Jan 21 '16 at 7:19