# Highlight line in plot

I have a plot with many functions. Some of the functions overlap. In Maple, when you plot functions with legends, you can just click on the legend and it highlights the corresponding line. Does something similar exist in Mathematica?

## SetterBar

colors = ColorData[1, "ColorList"][[;; 5]];

Dynamic[Legended[
Plot[Evaluate[Table[i Sin[i x], {i, 1, 5}]], {x, 0, 2 π},
PlotStyle -> ReplacePart[Table[{colors[[i]], Thin}, {i, 5}],
{Alternatives @@ n, 2} -> Thickness[.01]]],
SetterBar[Dynamic[n], Table[i ->
Grid[{{Pane[Style[Sin[i x], 16, Bold, "Panel", Opacity, colors[[i]],
Background -> Opacity], ImageSize -> {60, 30}],
Plot[Sin[i x], {x, 0, 2 π}, PlotStyle -> colors[[i]],
Axes -> False, ImageSize -> 40]}}], {i, 1, 5}],
Appearance -> "Vertical"]]] ## TogglerBar

Replace SetterBar above with TogglerBar: In versions prior to version 11., we can also use

Dynamic[Plot[Evaluate[Table[i Sin[i x], {i, 1, 5}]], {x, 0, 2 π},
PlotStyle -> ReplacePart[Table[{colors[[i]], Thin}, {i, 5}],
{Alternatives @@ n, 2} -> Thickness[.01]],
PlotLegends -> SetterBar[Dynamic[n], Table[i ->
Grid[{{Pane[Style[Sin[i x], 16, Bold, "Panel", Opacity, colors[[i]],
Background -> Opacity], ImageSize -> {60, 30}],
Plot[Sin[i x], {x, 0, 2 π}, PlotStyle -> colors[[i]],
Axes -> False, ImageSize -> 40]}}], {i, 1, 5}],
Appearance -> "Vertical"]]]


to get the same result (Similarly, for TogglerBar).

• That is awesome!!! Thanks kglr. I appreciate it. This is exactly what I was looking for. Jan 19 '18 at 15:10
• @Karim, my pleasure. Thank you for the accept. Welcome to mma.se.
– kglr
Jan 19 '18 at 15:11
• On my system, using Mathematica 11.2 under macOS, the setter and toggle bars are arrayed horizontally, rather than, as your images show, vertically. What's wrong? Jan 19 '18 at 22:58
• @murray, i am using version 9 on windows 10. I just confirmed the same issue on version 11 on Wolfram Cloud. A workaround is to use Legended instead of PlotLegends: ...
– kglr
Jan 19 '18 at 23:12
• ... that is, Dynamic[Legended[Plot[Evaluate[Table[i Sin[i x], {i, 1, 5}]], {x, 0, 2 \[Pi]}, PlotStyle -> ReplacePart[Table[Thin, {5}], Thread[ n -> Thickness[.01]]]],TogglerBar[Dynamic[n], Table[i -> Grid[{{Pane[ Style[Sin[i x], 16, Bold, "Panel", Opacity, colors[[i]], Background -> Opacity], ImageSize -> {60, 30}], Plot[Sin[i x], {x, 0, 2 \[Pi]}, PlotStyle -> colors[[i]], Axes -> False, ImageSize -> 40]}}], {i, 1, 5}], Appearance -> "Vertical"] ]] works as expected.
– kglr
Jan 19 '18 at 23:12