In using Manipulate
to illustrate selectively function dynamics I encountered the following difficulty with the PlotLegends
option. There are three plots, which can be selected through the 'function' variable check boxes. They display separately or in combination. The PlotLegends
option, however, only displays the legend labels in order, starting from the first one, regardless of which 'function' boxes are selected.
Manipulate[Plot[Evaluate[function /. t -> tt], {x, -2 Pi, 2 Pi}, PlotRange -> {-2, 2},
PlotLegends -> {"Re[e^i(x-t)+e^i(x+t)]", "Re[e^i(x-t)]", "Im[e^i(x+t)]"}],
{{function, {Re[Exp[I (x - t)] + Exp[I (x + t)]]}},
{Re[Exp[I (x - t)] + Exp[I (x + t)]] -> "Re[e^i(x-t)+e^i(x+t)]",
Re[Exp[I (x - t)]] -> "Re[e^i(x-t)]", Im[Exp[I (x + t)]] -> "Im[e^i(x+t)]"},
CheckboxBar}, {{tt, 0, "t = 0 to 2Pi "}, 0, 2 Pi}]
Two illustrating images, showing mismatched function selection and plot legends, are included below.
I shall be grateful for any suggestions how to set the plot legends, so that they always correspond correctly to any combination of the function plot selections. (There could be a trivial answer, but I have not succeeded in finding it.)
PlotLegends -> function
? $\endgroup$