# adding labels to points in ListPlot

Table[{Re[5 Exp[I 5/2 t]], Im[5 Exp[I 5/2 t]]}, {t, 0, 6}]
ListPlot[%]


This code plots 6 points in the complex plane. To each point I would like to add a label in the plot that lists the value of t. How can I do that?

Please note: I want to print this plot, so the labels should all be visible.

-

All plotting functions are just wrappers for Graphics objects. Show can be used to combine these objects, and that's one way of doing what you want here.

Take the following code as a starting point; you will of course have to tweak the positions of the labels (right now it's just a radial factor that offsets them). Note that I modified the data variable so that it includes $t$; it is now of the form {t, Re, Im}. The ListPlot will plot only the real and imaginary parts (data[[All, {2, 3}]]), while the Text passage also takes into account the value of $t$.

data = Table[{t, Re[5 Exp[I 5/2 t]], Im[5 Exp[I 5/2 t]]}, {t, 0, 6}];
dataPlot = ListPlot[data[[All, {2, 3}]], PlotStyle -> PointSize -> Large];
labels = Text[#[[1]], 1.1 #[[{2, 3}]]] & /@ data;
Show[
dataPlot,
Graphics[{Red, labels}],
PlotRange -> 6 {{-1, 1}, {-1, 1}},
AspectRatio -> 1
]


You can of course generalize this arbitrarily, e.g. color the labels differently, change font size etc. I kept the above to a minimum to avoid cluttering, the rest is up to you.

-
Why don't you use an offset for Text? – user21 Feb 16 '12 at 9:25
I felt like a factor fits the radial symmetry nicer here, but you're of course not limited to that. – David Feb 16 '12 at 12:49
I think, this does not behave well: data = Table[{t, Re[5 Exp[I 5/2 t]], Im[5 Exp[I 5/2 t]]} + 20, {t, 0, 6}]; dataPlot = ListPlot[data[[All, {2, 3}]], PlotStyle -> PointSize -> Large]; labels = Text[#[[1]], 1.1 #[[{2, 3}]]] & /@ data; Show[dataPlot, Graphics[{Red, labels}], AspectRatio -> 1] – user21 Feb 16 '12 at 13:34
Well you just added 20 to all imaginary parts. If you want a text offset, you'll have to change the 1.1 #[[{2, 3}]] to something like #[[{2, 3}]]+{1,1}. – David Feb 16 '12 at 13:52
The point is that with the third argument to Text you do not have to change anything. – user21 Feb 16 '12 at 14:17

Just discovered this thread while looking for an answer to the same question and figured I probably couldn't help the OP now, but decided to provide the answer I found for posterity.

You could wrap each point you're plotting in the Labeled function like so:

Table[
Labeled[
{Re[5 Exp[I 5/2 t]], Im[5 Exp[I 5/2 t]]},
t
]
, {t, 0, 6}];
ListPlot[%]


Labeled has options to control placement and whatnot. All in the documentation.

-
This code does not work... – geordie Nov 14 '13 at 23:37
@geordie It does for me on 9.0.1. You probably are using an old version... not really the OP's fault or downvote worthy, imo. – R. M. Nov 15 '13 at 0:14
Fair enough. Apologies to the OP. – geordie Nov 15 '13 at 5:10
How would I alter that if my data set were a list of pairs and I didnt have to use Table ? eg data={{1,2},{3,4},{5,6}} and labels={a,b,c}. – Lara Jordan Jan 21 '14 at 11:08

data = Table[
Tooltip[{Re[5 Exp[I 5/2 t]], Im[5 Exp[I 5/2 t]]}, t], {t, 0, 6}]
ListPlot[data]


A little bit of a hack...

data = Table[{coord = {Re[5 Exp[I 5/2 t]], Im[5 Exp[I 5/2 t]]},
Text[t, coord, {-2, 0}]}, {t, 0, 6}]
Show[ListPlot[data[[All, 1]]], Graphics[data[[All, 2]]]]


-