# How to display (x,y) coordinates in a listplot graph

I need to plot a listplot with its $(x,y)$ coordinate when my mouse go over a value of the function.

I want the simplest way to do it.

I have read topic using the notations "#", I just learnt how it works but if you use it I would like to have some explanations (that also could be an example for me to understand well how it works).

• Try right-clicking the plot and use "Get Coordinates? tool – Shadowray May 30 '17 at 12:39
• The problem is it is referenced to the origin of the picture. When i resize it it doesn't correspond. What's more it returns values where my mouse is and i just want a value on the function to have the exact result – StarBucK May 30 '17 at 12:40

## Data

Fake data, you use your own.

data = Transpose[{Range, RandomReal[1, 10]}];


## Simple solution

Auxiliary function to add Tooltip

addXYToolTip[{x_, y_}] := Tooltip[{x, y}, {x, y}]

ListPlot[
] ## Better solution

data2 = Transpose[Sort /@ RandomReal[1, {2, 20}]]
addXYToolTip2[{x_, y_}, {n_}] := Tooltip[
{x, y}
, Framed@Grid[
{
{"n: ", n},
{"x: ", x},
{"y: ", y}
},
Alignment -> Left]
]

ListPlot[
] In:

xss = Table[{x, Sin[x]}, {x, 0, 2 Pi, 0.05}];
mouseover[c_] := Mouseover[c, Text[c, c + {-0.2, 0.2}]]
plot[xss_] := xss // Map[mouseover] // ListPlot
plot[xss]

• interesting!!!! – partida May 31 '17 at 0:00

You can use Nearest + Dynamic as follows:

(* sample data *)
data=Table[{x,Sin[x]},{x,0,Pi,.1}];

(* nearest function *)
nf=Nearest[data];

ListPlot[
data,
Epilog -> Dynamic @ DynamicModule[
{
pt=nf[MousePosition[{"Graphics",Graphics},{0,0}]],
scaled=MousePosition[{"GraphicsScaled",Graphics},None]
},

If[scaled===None,
{},
{
Text[pt[], pt[], {1.5 Sign[scaled[]-.5], 0}, Background->White],
AbsolutePointSize, Point[pt], White, AbsolutePointSize, Point[pt]
}
]
]
] As long as the mouse pointer is in the graphic, the nearest data point will get highlighted.