1
$\begingroup$

Is it possible to make a plotted curve interactive in the sense that when hovering over it a line is drawn from the "hovered" point to one (or both) of the axes. I did do my homework, I just can't figure it out.

Edit: Let's say I plot this curve:

Manipulate[Plot[Sin[a x],{x,0,Pi}],{a,1,5}]

Whenever the mouse hovers over a point on the curve a line is drawn from that point to the x-axis.

$\endgroup$
0

2 Answers 2

8
$\begingroup$

Something like this?

DynamicModule[{mp, x, y, fun},
 fun[x_, a_] := Sin[a x];
 Manipulate[
  mp = MousePosition["Graphics"];
  If[mp === None,
   epi = {},
   {x, y} = mp;
   epi =
    If[
     Abs[y - fun[x, a]] < 0.1,
     Line[{{x, 0}, {x, fun[x, a]}}],
     {}
     ]
   ];
  Plot[fun[x, a], {x, 0, Pi}, Epilog -> epi]
  , {a, 1, 5}
  ]
 ]

Mathematica graphics

$\endgroup$
5
$\begingroup$
 Manipulate[Plot[Sin[a x], {x, 0, 10}, 
 Epilog -> {Red, Thick, Line[Dynamic[{{First[pt], 0}, 
         {First[pt],Sin[a First[pt]]}}]]}], 
 {a, 1, 5}, 
 {{pt, {0, 0}}, ControlType -> Locator, Appearance -> None, AutoAction -> True}]

enter image description here

 Manipulate[
 Plot[Sin[a x], {x, 0, 10}, 
 Epilog -> {Red, Thick, Line[Dynamic@{{First[pt], 0}, {First[pt], Sin[a First[pt]]}}], 
  Line[Dynamic@{{0, Sin[a First[pt]]}, {First[pt], Sin[a First[pt]]}}], 
  Black, PointSize[.03], Point[Dynamic@{First[pt], Sin[a First[pt]]}]}], 
 {a, 1, 5}, {{pt, {0, 0}}, ControlType -> Locator, Appearance -> None, 
 AutoAction -> True}]

enter image description here

$\endgroup$

Your Answer

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