In gnuplot, how to label each point in the plot with its coordinates?

hkchakladar picture hkchakladar · Apr 20, 2014 · Viewed 35.6k times · Source

I have a data file, abc.dat and I want to plot it with labeling each coordinate like (1,5), (4,6), (2,8) and so on ....

abc.dat is like :

1  5
4  6
2  8
4  5
7  8
8  9
3  4

Answer

Christoph picture Christoph · Apr 20, 2014

Use the labels plotting style for this. That requires three using specifiers: x-value, y-value and a string which is placed at the given coordinates. So the easiest command would be:

plot 'abc.dat' using 1:2:(sprintf("(%d, %d)", $1, $2)) with labels notitle

That places the respective labels centered at the coordinates.

The following command plots a point at the respective coordinate and places the coordinate label a bit shifted near to it:

set offset 1,1,1,1
plot 'abc.dat' using 1:2:(sprintf("(%d, %d)", $1, $2)) with labels point  pt 7 offset char 1,1 notitle

The result with 4.6.4 is:

enter image description here