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.
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.
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.
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.
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
}]
]
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]]