# How to copy Coordinates of “Get Coordinates” in Figure?

I am trying to reproduce the answer here about Recovering data points from an image. I click the figure and press "Get Coordinates". I would like to copy the four coordinates by CTRL-C and then paste it to a newline by CTRL-V. However, it does not work. Systems tested: Ubuntu 16.04 64 bit, Linux Mint 17.

JasonB. The article Get Coordinates for Points in a Plot shows that you should be able to copy-paste the coordinates by CTRL-C/V but it does not work stably. I would like to understand why.

How can you copy coordinates of "Get Coordinates" in Figure?

• From this page you should be able to just click on a series of points after selecting "Get Coordinates", and then just hit copy and they are copied to the clipboard. But this doesn't work for me (linux mint 17) because copy/paste functionality almost never works for me – Jason B. May 3 '16 at 15:38
• @JasonB Excellent source! Then, the task is to understand why it does not work OR if there is another way to copy them without the keybinding. – Léo Léopold Hertz 준영 May 3 '16 at 15:39
• I've just gotten used to the fact that MMA can't interact with my system clipboard very well. – Jason B. May 3 '16 at 15:46
• @JasonB Yes. Is there any other way to copy those points than the keybinding? – Léo Léopold Hertz 준영 May 3 '16 at 15:48
• 9 times out of 10, I can't even get it to work using the Edit menu, sorry – Jason B. May 3 '16 at 15:49

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

• Can you please add an example how you call your function. – Léo Léopold Hertz 준영 May 4 '16 at 12:02
• @Masi, Added one. You can also send the a plot by name, like image1 = Plot[Sin[x], {x, 0, 10}, ImageSize -> 400]; getCoordinates[image1, points] – Jason B. May 4 '16 at 12:15

You might try to use Locatorfor this purpose. Try this:

    coord = {};

DynamicModule[{pt = ImageDimensions[im]/2 // N},
Column[{
Show[{
image,
Graphics[Locator[Dynamic[pt]]]
}],
Dynamic[pt],
Button["Get coordinates", Clear[coord]; coord = pt]
}]
]


where ´image` is the name of your image and coord is the global variable. You find the right place for the locator while reading the coordinates under the image, if necessary. As soon as you have a right place, press the button and the global variable, coord, will contain the chosen coordinates.

Have fun!

• Can you please explain little more how these commands work. So you propose this package reference.wolfram.com/language/ref/Locator.html – Léo Léopold Hertz 준영 May 3 '16 at 15:47
• @Masi You should go to Menu/Help/Wolfram Documentation and type there the commands, such as Locator and others and you will get their detailed explanation. If after that you have questions, do ask them. – Alexei Boulbitch May 4 '16 at 9:57