## Highlight line in plot

12

3

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?

15

## 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[1], colors[[i]],
Background -> Opacity[0]], 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[1], colors[[i]],
Background -> Opacity[0]], 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. – Karim – 2018-01-19T15:10:14.197

@Karim, my pleasure. Thank you for the accept. Welcome to mma.se. – kglr – 2018-01-19T15:11:09.843

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? – murray – 2018-01-19T22:58:41.353

@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 – 2018-01-19T23:12:10.070

1... 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[1], colors[[i]], Background -> Opacity[0]], 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 – 2018-01-19T23:12:17.637