## Get Coordinates: New in 6.0.2

March 11, 2008 — Christopher Carlson, Senior User Interface Developer, User Interfaces

Many new features in *Mathematica* are manifested in new functions with definite names, but some are not so prominent. You might miss one of the new features that I implemented for *Mathematica* 6.0.2—but it’s really useful, and so I thought I’d write about it here.

Let’s say you have a plot, or some other kind of graphic. You see something in the graphic—some special point—and you want to know where that is, what its (*x*, *y*) coordinates are.

In earlier versions of *Mathematica*, there were primitive ways to find this out. Now in *Mathematica* 6.0.2 there’s a nice, clean, general way to do it.

Open the Drawing Tools palette (from the Graphics menu, or by typing CTRL-d or CTRL-t). Choose the “Get Coordinates” tool at the upper right.

Now when you hover over a graphic, the graphical coordinates of the point are shown next to the cursor.

It’s easy to use the tool to annotate the graphic with the coordinates of the point. Click the point—which will leave an orange dot marker in the graphic—then use the Copy command to put the coordinates of the point on the clipboard. Choose the Text tool from the Drawing Tools palette, click in the graphic where you want to add text, and then paste the coordinates from the clipboard. Edit the text to remove the outer braces, draw an arrow from the text to the point, and you’re done.

You can mark any number of points in a graphic, and use the copied coordinates in calculations. Here is an aerial photo of the Pentagon in a coordinate system where one unit equals one foot.

I wanted to find the length of a side, so I used the Get Coordinates tool to mark two of the Pentagon’s corners. I copied the coordinate values to the clipboard and then pasted them into a distance calculation:

Roughly 940 feet! That’s enormous! How much area does this thing enclose? I marked all five corners, copied the coordinates to the clipboard, and pasted them into the calculation of the area of a polygon:

Nearly 1.5 million square feet! What do they use to polish the floors? Zambonis?

You can mark more than just individual points with the Get Coordinates tool. To mark a series of points along a path, drag along the path. To mark a rectangular area, Alt-drag or Option-drag from one corner to the other. Here is an example of how I used Get Coordinates to indicate an area in an image and make a enlarged image of the area.

I grabbed a picture from `ExampleData`, a rich source of data very useful for performing tests and experiments. Using the Get Coordinates tool, I marked the rectangular area I wanted to zoom into, and copied the coordinates of the area to the clipboard.

Then I wanted to make two images, one showing the enlarged area in the context of the original image, and one showing the enlarged area itself. Both are easier than you might expect. To mark the original image, I used the `Epilog` option, pasting the copied coordinates into a `Rectangle` that indicates the enlarged area.

To make the enlarged image, I simply pasted the copied coordinates into a new `PlotRange`:

The usefulness of the Get Coordinates tool goes far beyond just marking points in graphics. That’s because you can customize what is displayed in the tooltip via the `CoordinatesToolOptions` option. The suboption `"DisplayFunction"` specifies a function that is applied to the cursor coordinates to yield the contents of the tooltip. You can display any information that can be calculated from the cursor coordinates.

Here’s an example where the raw cursor coordinates displayed by default are not very revealing. I made a plot of word frequencies in the Declaration of Independence. By default the Get Coordinates tooltip displays something like {30.18, 4.694}—not very helpful here. But I was able to use those coordinates to access the data from which the plot was made, and display in the tooltip the word graphed at the cursor position and its frequency. With that, I could easily explore the relative word frequencies represented in the plot.

Built-in plot functions like `PolarPlot` and `LogPlot` specify `CoordinatesToolOptions` in their outputs so that the Get Coordinates tool returns the coordinates you’d expect: for `PolarPlot`, polar {r, θ} coordinates instead of the raw {x, y} cartesian graphics coordinates.

As often happens with new *Mathematica* features, soon after the implementation of the Get Coordinates tool I discovered uses for it that I didn’t anticipate. That isn’t entirely coincidence: we strive to design in enough generality and flexibility in *Mathematica* features that that can happen.

Since *Mathematica* is so highly integrated, you can put any object into the Get Coordinates tooltip, including complex typeset structures and graphics. I used that capability to display in the tooltip a graph of the horizontal cross-section of a contour plot at the cursor position. It takes surprisingly little code to do so:

There are no doubt many more exotic uses for the new Get Coordinates tool. If you discover some good ones, let us know. And if you know of any good used Zambonis, I’m sure the Pentagon would like to hear from you.

## 4 Comments

Is there a way, perhaps using Get Coordinates or other, to convert an image of a graph (or chart) to the associated raw data points? One may first need to indicate the origin of the coordinate system.

Thanks – Karlito Bonnevie

Very helpful, I like this post!

Thanks

Nice post