Is there a way to obtain the coordinate of a point of interest in a ListPlot
?
As an example, I have a list containing many sets of 2D coordinates and the plot drawn is discontinuous at one point (the first derivative is not continuous and the gradient increases suddenly).
Can I extract the location of that point interactively? Otherwise, I have to search through the list of data myself to determine the change of gradient, which defeats the whole purpose of drawing a plot. Also, using the Get Coordinates function from the right click menu does not give very accurate results.
Answer
ListPlot
accepts data wrappers besides Tooltip
(although I could not find any mention of this feature in the docs).
So, @Jens' method can be achieved without post-processing:
data = Table[{Sin[n], Sin[2 n]}, {n, 50}];
ListPlot[PopupWindow[Tooltip[#], #] & /@ data]
On mouseover:
Click on a point:
Note: Thought this was a new feature added in Version-9, but as @Alexey Popkov noted it also works in version 8.0.4, so it has been around for some time.
Update: A simpler version of @Mr.Wizard's printTip
can also be used as a wrapper directly inside ListPlot
:
ListPlot[Button[Tooltip@#, Print[#]] & /@ N@data]
Update 2: Collecting point coordinates:
clicks = {};
Column[{ListPlot[Button[Tooltip@#, AppendTo[clicks, #]] & /@ N@data,
ImageSize -> 300],
"\n\t", Row[{"clicks = " , Dynamic[clicks // TableForm]}]}]
Comments
Post a Comment