Gnuplot: Shortest way to ignore first line in datafile

Gnuplot can read column names from the first line, but you can still specify the column names normally as well. Therefore, this effectively skips the first line.

Issue the command

set key autotitle columnhead

This tells gnuplot that the first line is not data, but is the column names to be used for the key. You can still unset key or plot datafile title sometitle the same as you could before, and gnuplot will just not use that data.

Suppose that my file looks like

1 2
4 5
7 8

I can just issue set key autotitle columnhead follwed by unset key (if I don’t really want a key), and it will skip the first line.

enter image description here


Alternatively, I can pipe my data through an external program. For example, using awk (which is available for most OS’s including Windows), I can do

plot "< awk '(NR>2){print;}' datafile"

to skip the first 2 lines (using Windows, I must do '< awk "(NR>2){print;}" datafile'). If I don’t want to keep typing this, I can store this in a string

skipfile = "\"< awk '(NR>2){print;}' datafile\""

and use it as a macro (for Windows, use skipfile=""< awk \"(NR>2){print;}\" datafile""). For instance, to plot the datafile using lines, I might do

plot @skipfile with lines

The @skipfile just tells gnuplot to treat the command like I had just typed the contents of skipfile right there.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)