How to label (x,y) data points in Gnuplot 4.2 with integer numbers

gnuplot

Solution

You can use the `with labels` flag to the plot command. By default this places the label instead of the point at the place where the point would be. `with label` takes the `offset` flag (and any flag you can pass to `set label`) so you can have the label next to the point. Here is an example script:

#!/usr/bin/env gnuplot

reset

set terminal pngcairo
set output 'test.png'

set xr [0:5]
set yr [0:6]

plot 'data.dat' pt 7, \
     'data.dat' using 1:2:($0+1) with labels offset 1 notitle

which produces this output:

Problem

I have a text file with 2 columns of numbers corresponding to (x,y) coords. ``` 4 1 4 5 1 1 1 5 2.5 3 ``` How do I tell gnuplot to plot these points and label each point with its corresponding row #? (Please keep in mind I'm going to apply this to a much larger file with 100 points, so I'm looking for a way to do it automagically, rather than have to create a 3rd column of data corresponding to row numbers).

Original source