# Preserving the colours with Manipulate

I am trying to get the correct colors for my curves. I have this code

color = {Red, Green, Blue};
names = {"cat", "dog", "rat"};
Manipulate[
Legended[
Plot[Sin[k x], {x, 0, 3 Pi}, PlotStyle -> color[[k]]],
Placed[LineLegend[color, names, LegendLayout -> "Row"],
Below]], {{k, {1, 3}}, {1, 2, 3}, ControlType -> CheckboxBar}]


Which instead of assigning color[[k]] (red green and blue) to each curve, it assign the same colour to every curve.

I have already asked a similar question and there is a post which does exactly this, though for a ListLinePlot (last image). I've tried so many different things but none really does the trick.

It is kind of important that I do this in the most simple way because this is a MWE part of a bigger script. In particular I would like to keep the flexibility to increase the number of colors/names without having to modify anything inside the Manipulate.

Using Evaluate@Sin[k x] will handle this issue.

color = {Red, Green, Blue};
names = {"cat", "dog", "rat"};
Manipulate[
Legended[Plot[Evaluate@Sin[k x], {x, 0, 3 Pi},
PlotStyle -> color[[k]]],
Placed[LineLegend[color, names, LegendLayout -> "Row"],
Below]], {{k, {1, 3}}, {1, 2, 3}, ControlType -> CheckboxBar}]


• I can't believe it's as easy as that. I've spent a day trying to solve this. Why do I have to Evaluate it to have the correct colors? – Manfredo Nov 27 '17 at 15:06
• @Manfredo check this mathematica.stackexchange.com/questions/1731/… – zhk Nov 27 '17 at 16:53