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?

  • 1
    $\begingroup$ 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 $\endgroup$ – Jason B. May 3 '16 at 15:38
  • $\begingroup$ @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. $\endgroup$ – Léo Léopold Hertz 준영 May 3 '16 at 15:39
  • 1
    $\begingroup$ I've just gotten used to the fact that MMA can't interact with my system clipboard very well. $\endgroup$ – Jason B. May 3 '16 at 15:46
  • $\begingroup$ @JasonB Yes. Is there any other way to copy those points than the keybinding? $\endgroup$ – Léo Léopold Hertz 준영 May 3 '16 at 15:48
  • 1
    $\begingroup$ 9 times out of 10, I can't even get it to work using the Edit menu, sorry $\endgroup$ – 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 = {};
 Column[{Dynamic[MousePosition["Graphics", "Out of range"]],
 AppendTo[pts, #] &

enter image description here

You can make a function out of this via

SetAttributes[getCoordinates, HoldAll];
getCoordinates[image_, pts_] := Module[{},
  pts = {};
   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,

 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

  • $\begingroup$ Can you please add an example how you call your function. $\endgroup$ – Léo Léopold Hertz 준영 May 4 '16 at 12:02
  • 1
    $\begingroup$ @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] $\endgroup$ – 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},
   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!

  • $\begingroup$ Can you please explain little more how these commands work. So you propose this package reference.wolfram.com/language/ref/Locator.html $\endgroup$ – Léo Léopold Hertz 준영 May 3 '16 at 15:47
  • $\begingroup$ @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. $\endgroup$ – Alexei Boulbitch May 4 '16 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.