This turned out to be pretty simple, using ClickPane
to capture the clicks, and MousePosition
so that you can see the current coordinates.
After running the code below, and placing your mouse over the plot, the coordinates are displayed above the plot. After clicking, the coordinates you click are added to the list pts
. This bypasses any interaction with the clipboard, which is desirable because it doesn't work very well in Linux (or at least in my installation).
image = Plot[Sin[x], {x, 0, 10}, ImageSize -> 400];
pts = {};
ClickPane[
Column[{Dynamic[MousePosition["Graphics", "Out of range"]],
image}],
AppendTo[pts, #] &
]
You can make a function out of this via
SetAttributes[getCoordinates, HoldAll];
getCoordinates[image_, pts_] := Module[{},
ClearAll@pts;
pts = {};
ClickPane[
Column[{Dynamic[MousePosition["Graphics", "Out of range"]],
image}], AppendTo[pts, #] &]
];
The first argument of the function is the plot, and the second is the variable to which you want to assign the coordinates list. For example,
getCoordinates[
DensityPlot[Sin[x^2 - y], {x, -5, 5}, {y, -5, 5},
PlotPoints -> 50], mypointslist]
After entering the above, I click around a few times collecting points, and the points are stored in the list mypointslist
Edit
menu, sorry $\endgroup$