Message Boards Message Boards

0
|
4273 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Better way to display coordinates of a point than using the TEXT command?

Posted 8 years ago
p1 = Graphics[{PointSize[Large], Black, Point[{4, 2}], 
    Text["(4,2)", {4, 2.1}]}];
p10 = Graphics[{Thick, Green, Rectangle[{1, 0}, {4, 2}]}];

Show[p10, p1]  

See attachment.

Attachments:
POSTED BY: Mitchell Sandlin
4 Replies

If you insist on round parentheses for (x,y) couples, you label the points this way:

labeledPoint[{x_, y_}] := {Point[{x, y}], 
   Text[Row[{"(", x, ",", y, ")"}], {x, y}, {-1, -1}]};
points = {{0, 0}, {1, 0}, {4, 0}, {1, 2}, {4, 2}};
Graphics[Map[labeledPoint, points]]
POSTED BY: Gianluca Gorni
Posted 8 years ago

You could try something like this:

With[
    {points =
        {{0, 0}, {1, 0}, {4, 0}, {1, 2}, {4, 2}}
    },
    Graphics[{
        Green, Rectangle[points[[2]], points[[5]]],
        PointSize@Large, Black,
        Point@points, Text[#, # + {0, 0.1}] & /@ points
    }]
 ]    

Using Tooltip instead of text:

With[
    {points =
        {{0, 0}, {1, 0}, {4, 0}, {1, 2}, {4, 2}}
    },
    Graphics[{
        Green, Rectangle[points[[2]], points[[5]]],
        PointSize@Large, Black,
        Point@points, Tooltip[Point@#, Text@#] & /@ points
    }]
 ]
POSTED BY: Hans Milton

Actually I am looking for a better way to obtain and then display the data (x and y coordinates) other than hardcoding the x and y coordinates into a Text command. I like the Tooltip command, but even with this command, it seems that you need to hardcode in the x and y coordinates.

POSTED BY: Mitchell Sandlin

This depends on what you mean by "better". What do you want to achieve?

A first comment: there's no reason to use Show in your code--just put everything in a Graphics:

Graphics[{Thick, Green, Rectangle[{1, 0}, {4, 2}], PointSize[Large], 
  Black, Point[{4, 2}], Text["(4,2)", {4, 2.1}]}]

As an alternative to having the text visible in the graphic using Text you can always use a Tooltip as in

Graphics[{Thick, Green, Rectangle[{1, 0}, {4, 2}], PointSize[Large], 
  Black, Tooltip[Point[{4, 2}], "(4,2)"]}]

then mousing over the point shows the desired text. But depending on what "better" means, I am sure there are many many possibiltles.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract