I have used Manipulate in conjunction with Plot to draw a function's graph and I would like to show the current x-axis value and function value while hovering over the function's plot. How can I achieve this?
Thanks.
Manipulate[
Module[{tbl},
tbl = Table[Tooltip[{x, Sin[a x]}], {x, -Pi, Pi, .1}];
ListLinePlot[tbl, Mesh -> All, MeshStyle -> Opacity[0]]
],
{{a, 1, "a?"}, .1, 5, .1}
]
Tooltip
iterator.
$\endgroup$
Alternative that avoids the flicker of Tooltip (copying & adapting @Nasser):
f[x_, a_] := Sin[a x^3];
p = {0, 0};
Manipulate[
EventHandler[
Plot[f[x, a], {x, -Pi, Pi},
Prolog -> Dynamic@{Thin,
Line[{{p[[1]], 0}, {p[[1]], f[ p[[1]], a]}, {0, f[ p[[1]], a]}}],
Point[{p[[1]], f[ p[[1]], a]}]},
PlotLabel ->
Dynamic@{p[[1]], f[ p[[1]], a]}],
{"MouseMoved" :> (p = If[# =!= None, #, p] &@MousePosition["Graphics"])}],
{{a, 1, "a?"}, .1, 5, .1}]
It also takes advantage of Plot
's adaptive graphing methods to deal with wiggly graphs.
p = MousePosition["Graphics", p]
.
$\endgroup$
Tooltip
any use? $\endgroup$