5
$\begingroup$

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:

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.

$\endgroup$

2 Answers 2

4
$\begingroup$

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"}]

enter image description here

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

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}]

enter image description here

Colors for lines taken from Match colors to plot themes

$\endgroup$
2
  • 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$ Jan 21, 2016 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, 2016 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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