Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
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.

share|improve this question

3 Answers

up vote 15 down vote accepted

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
]

enter image description here

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.

share|improve this answer
2  
Why don't you use an offset for Text? – ruebenko 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] – ruebenko 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. – ruebenko Feb 16 '12 at 14:17
show 1 more comment

How about:

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

Mathematica graphics

share|improve this answer
Tooltip seems useful on screen. However, I want to print this plot with all the labels in it. Is there an alternative for Tooltip? – sjdh Feb 16 '12 at 8:22
@Mr.Wizard, did not read the question properly - must go and get coffee. Thanks. – ruebenko Feb 16 '12 at 8:23
@Szabolcs, thanks for the picture. – ruebenko Feb 16 '12 at 11:40

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.