Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to turn a file like:

Name  X  Y
a     1  2
b     4  1
s     3  3

in a X-Y graphic with the X-Y dots labeled with Name.

How can I do it? I think this can be done with gnuplot, but I wasn't able to do it yet.

share|improve this question
    
I'm fairly certain gnuplot can do it too, but I'm no master, sorry. :( –  Paul Nathan Nov 7 '09 at 18:02

2 Answers 2

up vote 6 down vote accepted

You can put labels at a specified offset from the points using the following gnuplot command:

echo "plot 'file.dat' using 2:3 pt 2 notitle, '' using 2:3:1 with labels offset 0.5,0.5 notitle;" | gnuplot -persist

NB: works only if gnuplot has been compiled with --enable-datastrings (thanks to DaveParillo for the clarification)

share|improve this answer
    
+1 nice avoidance of a separate label file. I've always done it that way and didn't think there was any other way. –  DaveParillo Nov 8 '09 at 21:06
3  
FYI: If this example doesn't work for someone - the labels style is available only if gnuplot is built with configuration option --enable-datastrings –  DaveParillo Nov 8 '09 at 21:16

Gnu plot can't do this alone. I doesn't know what to do with the text. If your data exists in a file named file.dat, then:

perl -ane 'print "set label \"($F[0])\" at $F[1],$F[2]\n"' file.dat > label.plt

will produce a label file you can use in gnuplot. You can then produce a (very basic) plot like this:

gnuplot> load "label.plt"
gnuplot> plot 'file.dat' u 2:3

You can mess around with the label offset if you want. For example,

"set label \"($F[0])\" at $F[1]+0.05,$F[2]+0.05\n"'

moves the labels out a bit, so that they are not right up against your points.

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.