8

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.

2 Answers2

6

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)

mrucci
  • 10,234
2

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.

DaveParillo
  • 14,761