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

Labeling points

300 views
Skip to first unread message

AngleWyrm

unread,
May 15, 2008, 7:50:18 AM5/15/08
to
Here's a graphic I created for a discussion on game theory:
http://home.comcast.net/~anglewyrm/thread/dps.png

I put the text next to the points in as a post-processing step by hand in
PhotoShop.

Is there a way to get mathematica to display such information?

Szabolcs Horvát

unread,
May 16, 2008, 5:27:22 AM5/16/08
to

Here are some random points with labels:

points = Table[{RandomReal[1, 2], i}, {i, 10}]

If the graphic will be sent to people who have Mathematica 6, use Tooltip:

Graphics[Tooltip[Point[#1], #2] & @@@ points]

Otherwise you could use Text:

Graphics[{Point[#1], Text[#2, #1, {-3, 0}]} & @@@ points]


David Park

unread,
May 16, 2008, 5:28:06 AM5/16/08
to
pointsandvalues = {{.5, 50, 50}, {1, 50, 75}, {1.5, 50, 88}, {2.0, 50,
94}, {1.0, 100, 25}, {1.5, 100, 50}, {2.0, 100, 69}, {1.5, 150,
13}, {2.0, 150, 31}, {2.0, 200, 6}}

Graphics[
{AbsolutePointSize[4],
Module[{loc = Part[#, {1, 2}], val = Part[#, 3]}, {Point[loc],
Text[Row[{val, Spacer[2], "%"}], loc, {-1.8, 0}]}] & /@
pointsandvalues},
AspectRatio -> 1,
Axes -> True, AxesOrigin -> {0, 0}, AxesLabel -> {"Time", "Damage"},
ImageSize -> 300]

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


"AngleWyrm" <angl...@yahoo.com> wrote in message
news:g0h81q$mtp$1...@smc.vnet.net...

Jens-Peer Kuska

unread,
May 16, 2008, 5:28:39 AM5/16/08
to
Hi,

Graphics[
{Point[#],
Text[ToString[Round[Random[]*100]] <> " %", #, {1, -1}]} & /@
data, Frame -> True, PlotRange -> {{0, 1}, {0, 1}}]

??

Regards
Jens

Christopher Carlson

unread,
May 16, 2008, 5:29:12 AM5/16/08
to
On May 15, 2008, at 6:49 AM, AngleWyrm wrote:
> Here's a graphic I created for a discussion on game theory:
> http://home.comcast.net/~anglewyrm/thread/dps.png
>
> I put the text next to the points in as a post-processing step by
> hand in
> PhotoShop.
>
> Is there a way to get mathematica to display such information?


You can post-process plot output to add the information you want. For
example, here is a ListPlot:

plot = ListPlot[Table[{x, y}, {x, 1, 4}, {y, 1, x}], AxesOrigin -> {0,
0}]


Christopher Carlson
User Interface Group
Wolfram Research, Inc

J. McKenzie Alexander

unread,
May 16, 2008, 5:30:38 AM5/16/08
to
One way to annotate graphics like this is to use the Epilog option,
which allows you to specify arbitrary graphic constructs for inclusion
in the graphic.

To keep the Epilog option from becoming unreadable (and to give you
the change to tweak the appearance of the point/label pairs), here's a
simple function that generates the annotations:

f[lab_, pt_] := {Point[pt], Text[Style[lab, 14], pt, {-1.5, 0}]}

Your plot is then constructed as follows:

Plot[50 x, {x, 0, 2},
PlotRange -> {{0, 2.25}, {0, 200}},
PlotStyle -> Blue,
AspectRatio -> 1,


AxesLabel -> {"Time", "Damage"},

PlotRangeClipping -> False,
Epilog -> {
AbsolutePointSize[6],
Point[{0, 0}],
Point[{0.5, 0}],
Point[{1.5, 0}],
Point[{2.0, 0}],
f["50%", {0.5, 50}],
f["75%", {1, 50}],
f["88%", {1.5, 50}],
f["94%", {2, 50}],
f["25%", {1, 100}],
f["50%", {1.5, 100}],
f["69%", {2, 100}],
f["13%", {1.5, 150}],
f["31%", {2, 150}],
f["6%", {2, 200}]
}
]

Jason

On 15 May 2008, at 12:49, AngleWyrm wrote:

> Here's a graphic I created for a discussion on game theory:
> http://home.comcast.net/~anglewyrm/thread/dps.png
>
> I put the text next to the points in as a post-processing step by
> hand in
> PhotoShop.
>
> Is there a way to get mathematica to display such information?
>
>
>

--
Dr J. McKenzie Alexander
Department of Philosophy, Logic and Scientific Method
London School of Economics and Political Science
Houghton Street, London WC2A 2AE


Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm

Bob Hanlon

unread,
May 16, 2008, 5:34:26 AM5/16/08
to
data = {
{0.5, 50, "50%"},
{1.0, 50, "75%"},
{1.5, 50, "88%"},
{2.0, 50, "94%"},
{1.0, 100, "25%"},
{1.5, 100, "50%"},
{2.0, 100, "69%"},
{1.5, 150, "13%"},
{2.0, 150, "31%"},
{2.0, 200, "6%"}};

Plot[50 x, {x, 0, 2},

Epilog -> {AbsolutePointSize[5],
Point[Take[#, 2] & /@ data],
Text[#[[3]], #[[{1, 2}]], {-1.5, -.5}] & /@ data},
PlotRange -> {{0, 2.15}, {0, 210}},


AxesLabel -> {"Time", "Damage"},

AspectRatio -> 1]


Bob Hanlon

AnttiPenttilä

unread,
May 16, 2008, 5:36:36 AM5/16/08
to
Hi,

Labeled list plot was available in Mathematica 5. For some reason, it's
not available anymore in version 6, but you can use it by downloading
the package from the previous version from
http://library.wolfram.com/infocenter/MathSource/6808/

Then, after reading the package in by << or Get, try

LabeledListPlot[ {{0.5, 50, " 50%"}, {1, 100, " 25%"}, {1.5, 100,
" 50%"}}, PlotRange -> {{0, 1.7}, {20, 110}}]

Antti

Christopher Carlson

unread,
May 17, 2008, 5:36:40 AM5/17/08
to
On May 16, 2008, at 4:29 AM, Christopher Carlson wrote:

> On May 15, 2008, at 6:49 AM, AngleWyrm wrote:
>> Here's a graphic I created for a discussion on game theory:
>> http://home.comcast.net/~anglewyrm/thread/dps.png
>>
>> I put the text next to the points in as a post-processing step by
>> hand in
>> PhotoShop.
>>
>> Is there a way to get mathematica to display such information?
>
>
> You can post-process plot output to add the information you want. For
> example, here is a ListPlot:
>
> plot = ListPlot[Table[{x, y}, {x, 1, 4}, {y, 1, x}], AxesOrigin -> {0,
> 0}]

That first reply was truncated somehow. Here's the rest...

To add labels the the ListPlot output, I

(1) replace Point objects in the output with labeled Points,

(2) wrap the result with Show[..., PlotRangeClipping->False], which
prevents labels that fall outside of the plot range from being clipped.

Show[
plot /. Point[pts_] :> ({Point[#], Black, Text[Row[{IntegerPart[100
#[[2]]/5], "%"}], #, {-1.5, -1}]} & /@ pts),
PlotRangeClipping -> False]

angl...@yahoo.com

unread,
May 19, 2008, 6:23:45 AM5/19/08
to
Thanks all, great help! Combining them, here's what I wound up with:

(* Custom LabeledListPlot *)
LabeledListPlot[data_] :=
Show[Graphics[{PointSize[Last[#]/50], Point[Take[#, 2]],
Text[ToString[Round[100 Last[#]]] <> "%",
Take[#, 2], {-1.5, 0}]} & /@ data],
Axes -> True, AxesOrigin -> {0, 0}, AspectRatio -> 1,
AxesLabel -> {"Shots", "Damage"}];

(* Data supplied by other routines *)
data = {{1, 1, 0.5`1.9999999999999998}, {2, 1,
0.75`2.0000000000000004}, {2, 2, 0.25`1.9999999999999998}, {3, 1,
0.875`2.0000000000000013}, {3, 2, 0.5`1.9999999999999998}, {3, 3,
0.125`1.9999999999999998}, {4, 1, 0.9375`2.0000000000000004}, {4,
2, 0.6875`2.}, {4, 3, 0.3125`1.9999999999999998}, {4, 4,
0.0625`1.9999999999999998}, {5, 1,
0.96875`1.9999999999999991}, {5, 2, 0.8125`2.000000000000002}, {5,
3, 0.5`1.9999999999999998}, {5, 4,
0.1875`2.0000000000000004}, {5, 5,
0.03125`1.9999999999999998}, {6, 1,
0.984375`2.0000000000000004}, {6, 2,
0.890625`2.0000000000000004}, {6, 3,
0.65625`1.9999999999999998}, {6, 4, 0.34375`2.}, {6, 5,
0.109375`2.0000000000000013}, {6, 6,
0.015625`1.9999999999999998}};

LabeledListPlot[data]

Ray Koopman

unread,
May 21, 2008, 2:56:01 PM5/21/08
to
The visual system notices area, not diameter, so if you want the
subjective size of each point to be proportional to the third value
in each element of data you should use PointSize[Sqrt[Last[#]]/50]
instead of PointSize[Last[#]/50].
0 new messages