Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get Graphics Coordinates accuracy

60 views
Skip to first unread message

John Jowett

unread,
Sep 25, 2008, 5:30:39 AM9/25/08
to
I came across a limitation in the mechanism for copying coordinates of
points in 2D graphics (the Get Coordinates button in the Drawing Tools
palette) in V6.03.

Consider the following plot of a sine wave

Plot[Sin[2 x], {x, 20270, 20275}]

When I try to select and paste the coordinates of the two crests of
the wave, I typically get two points with the same x-coordinate

{{2.027*^4, 0.99}, {2.027*^4, 0.99}}

whereas I would expect the two x-coordinates to be around
20270.3 and 20273.5, values which are well separated on the plot.

This seems to happen because the Get Coordinates function only returns
the first 4 digits of the coordinates.

Does anyone know of a way to fix this ? Obviously, in this
demonstration example, I could change variables to x1=x-20270 but in
the more complicated problem I am working on, this is not so easy.

John Jowett

Message has been deleted

David Park

unread,
Sep 27, 2008, 6:50:23 AM9/27/08
to
John,

Before WRI reintroduced the GetCoordinates button in the DrawingTools
Palette in Version 6, I included commands to perform a similar operation
with the Presentations package. The user can apply a LocatorDraw or
LocatorLine[n] expression to a drawing statement and then obtain a display
showing the positions of the locators in the plot. These positions can then
be copied and pasted, even back into the plot if you want to add a Text
statement say. Then the LocatorDraw or LocatorLine[n] can be removed.

So here is your example done with Presentations.

Needs["Presentations`Master`"]

LocatorLine[2]@
Draw2D[
{Draw[Sin[2 x], {x, 20270, 20275}]},
Frame -> True,
ImageSize -> 400]

(* graphic with two locators connected by a line, then adjusted to the peaks
*)
Line[{{20270.3,0.98},{20273.5,0.999999}}]

When the points are copied out of the Line expression they give full
precision.
{{20270.345`,0.98`},{20273.515`,0.9999992007707353`}}

The GetCoordinates mechanism is convenient for many purposes but it has four
disadvantages of various degrees of severity. Least severe is that if you
copy only one point it has double brackets and for most uses you will have
to hand edit one pair of brackets out. Next is the problem you mention -
that it returns truncated precision. A third problem is that you have no
chance to adjust the points you want before copying. With locators you can
see and adjust what you have before copying.

A fourth problem is the whole concept of using Drawing Tools to edit a
graphic. (But perhaps that is not what you are doing in this particular
case.) With Presentations one can have a Draw2D statement with many elements
in it: curves drawn by different methods and various primitives and
directives. Now if you edit this with Drawing Tools, say to add some points
or a text label, you end with a second amended specification of the graphic,
which is in graphic form. Now suppose you wish to add something else to the
graphic that is not included in the Drawing Tools palette, say another
computed curve. You have to go back to the original statement. You have then
lost all the editing you did with Drawing Tools - and even worse there is no
textual record of what you did. It is much better, and more professional, to
have a single statement, in StandardForm say, that completely defines the
graphic.

Your actual problem sounds like one that might benefit from a dynamic
display, that might have a movable point restricted to the curve and would
also have a dynamic display of the coordinates, or slope or other computed
quantities.

--
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/


"John Jowett" <John.M...@gmail.com> wrote in message
news:gbflnv$682$1...@smc.vnet.net...

Jens-Peer Kuska

unread,
Sep 27, 2008, 10:21:05 PM9/27/08
to
Hi,

p = {20272.5, 0.5};

Plot[Sin[2 x], {x, 20270, 20275},
Epilog -> {Dynamic[Locator[Dynamic[p]]]}]

and

Dynamic[p]

Regards
Jens

m...@inbox.ru

unread,
Sep 28, 2008, 7:23:16 AM9/28/08
to

John Jowett wrote:
> I came across a limitation in the mechanism for copying coordinates of
> points in 2D graphics (the Get Coordinates button in the Drawing Tools
> palette) in V6.03.
>
> Consider the following plot of a sine wave
>
> Plot[Sin[2 x], {x, 20270, 20275}]
>
> When I try to select and paste the coordinates of the two crests of
> the wave, I typically get two points with the same x-coordinate
>
> {{2.027*^4, 0.99}, {2.027*^4, 0.99}}
>
> whereas I would expect the two x-coordinates to be around
> 20270.3 and 20273.5, values which are well separated on the plot.
>
> This seems to happen because the Get Coordinates function only returns
> the first 4 digits of the coordinates.
>
> Does anyone know of a way to fix this ? Obviously, in this
> demonstration example, I could change variables to x1=x-20270 but in
> the more complicated problem I am working on, this is not so easy.
>
> John Jowett

As a workaround, you can do

Plot[Sin[2 x], {x, 20270, 20275}, CoordinatesToolOptions ->
{"DisplayFunction" -> (#&),
"CopiedValueFunction" -> (SetPrecision[#, $MachinePrecision]&)}]

and then you can apply N to the copy-paste result to convert it back
to MachinePrecision.

Maxim Rytin
m...@inbox.ru

John Jowett

unread,
Oct 8, 2008, 6:25:07 AM10/8/08
to
Thanks (belatedly - I've been away from the newsgroup for a couple of
weeks) to David, Jens and Maxim for these interesting solutions.

I was surprised to learn from Maxim that Plot appears to have
undocmented options like CoordinatesToolOptions. I found some more
about this interesting option at

http://blog.wolfram.com/2008/03/11/get-coordinates-new-in-602/

John

0 new messages