Wolfram Blog
Christopher Carlson

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.

Click the crosshairs symbol on the Drawing Tools palette

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

Graphical coordinates of a point

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.

Annotated graphical coordinates of a point

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.

In[1]:= ArrayPlot[ExampleData[{

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:

In[2]:= EuclideanDistance[{365.1, 1689}, {1301, 1792}]

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:

In[3]:= Area[pts_] :=Abs[Plus @@ Det /@ Transpose[{pts, RotateLeft[pts]}]]/2;  In[4]:= Area[{{371.2, 1677}, {1295, 1786}, {1654, 947}, {967, 320.8}, {164.5, 764.6}}]

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.

In[5]:= lenaGraphic = ExampleData[{

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.

In[6]:= Show[lenaGraphic, Epilog -> {Opacity[.3], Rectangle[{242.5, 141.5}, {325, 272.4}]}]

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

In[7]:= Show[lenaGraphic, PlotRange->Transpose[{{242.5, 141.5}, {325, 272.4}}]]

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.

In[8]:= data = Take[Sort[Tally[ExampleData[{

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:

In[10]:= ContourPlot[Sin[x^2+y^2], {x, -4, 4}, {y, -4, 4}, CoordinatesToolOptions -> {

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.

Posted in: Mathematica News
Leave a Comment

4 Comments


Karlito Bonnevie

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

Posted by Karlito Bonnevie    July 22, 2009 at 2:55 pm
JerryMirro

Very helpful, I like this post!

Posted by JerryMirro    May 30, 2010 at 11:43 pm
Horoskop Miesieczny

Thanks

Posted by Horoskop Miesieczny    September 9, 2010 at 12:18 pm
Horoskop Bliznieta

Nice post

Posted by Horoskop Bliznieta    September 9, 2010 at 4:06 pm


Leave a comment

Loading...

Or continue as a guest (your comment will be held for moderation):