# How do I display the numeric value of a curve with Tooltip?

Using Tooltip, is it possible to display the numeric value of the curve I've plotted using Plot and PolarPlot?

For example, is it possible to display the numeric y value of Sin[x] (or any other curve) with Tooltip?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Jul 14, 2016 at 17:53
• Possible duplicate: mathematica.stackexchange.com/questions/17545/… -- seems to be the same idea as @user6014's answer below. Jul 14, 2016 at 17:57
• Also related: mathematica.stackexchange.com/questions/34672/… Jul 14, 2016 at 18:06
• See the "Get coordinates tool" in the docs
– Jens
Jul 14, 2016 at 18:10

I thought I did something like the following before, but maybe it was not for this site:

DynamicModule[{y0},
EventHandler[
Plot[Tooltip[Sin[x], Dynamic[y0]], {x, 0, 2 Pi}],
"MouseMoved" :> (y0 = Sin@First@MousePosition["Graphics"]),
]]


Update, per comment. Note that MousePosition["Graphics"] returns the coordinates of the mouse, not of a point on the graphics. It is triggered when the mouse is near the graphics, so it gives only a very rough approximation to the function value. One can take the x-coordinate of the mouse as given and calculate the y-coordinate from the function. If the function is complicated, one might not want to copy the code into both arguments of Tooltip; I use With below so one needs only to type the function expression once. (There's a red syntax warning on the x inside Dynamic, because Dynamic is HoldFirst and Plot effectively uses Block to assign x a value; but it's just what we need here, since Plot finishes evaluating before Dynamic reaches the front end.)

With[{f = Sin[x]},
Plot[
Tooltip[f,
Dynamic[f /. x -> First@MousePosition["Graphics"]]],
{x, 0, 2 Pi}]
]


Bells & whistles:

With[{f = Sin[x]},
DynamicModule[{x1, y1},
EventHandler[
Plot[
f,
{x, 0, 2 Pi},
MaxRecursion -> 0,
Epilog -> {Red, Dynamic@Tooltip[Point[{x1, y1}], {x1, y1}]},
GridLines -> {
Dynamic@If[NumericQ[x1], {x1}, None],
Dynamic@If[NumericQ[y1], {y1}, None]}
],
"MouseMoved" :> (
x1 = First@MousePosition["Graphics", {x1, 0}];;
y1 = f /. x -> x1)],
Initialization :> (
x1 = Pi; y1 = f /. x -> Pi)]]

• for minimal functionality this is enough Plot[Tooltip[Sin[x], Dynamic@MousePosition["Graphics"]], {x, 0, 2 Pi}]
– Kuba
Jul 14, 2016 at 18:38
• @Kuba D'oh! Thanks! (You can answer with that, if you like. But I'm tempted to close as dupe....) Jul 14, 2016 at 18:53

Potential way to achieve this:

pl = Plot[Sin[x], {x, 0, 10}];
vals = Table[Tooltip[{x, Sin[x]}, Sin[x]], {x, 0, 10, .05}];
lp = ListPlot[vals, PlotStyle -> None];
Show[{pl, lp}]