Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Jul 10 '12 at 21:01

This question came from our site for professional and enthusiast programmers.

    
@Nasser - You mean like proving RH and such? ;-) –  stevenvh Jul 11 '12 at 10:58

2 Answers 2

 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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.