gnuplot: for and columnheader command

Chris Bao picture Chris Bao · Oct 19, 2014 · Viewed 10.3k times · Source

I am planning to plot multiple columns data file. draw xy plot with the 1st column and the ith column. so the command for works based on the manual. which gnuplot version begin has such function? my machine install version4.2, but can not work. the same question for columnheader()
i want to make sure it is my code's issue or the version's.

Answer

Christoph picture Christoph · Oct 19, 2014

Version 4.2 already has the columnheader function.

Consider the data file data.txt which contains

first second third fourth
1 2 3 4
2 3 4 5
3 4 5 6

In gnuplot 4.2 you can use e.g.

set key autotitle columnheader
set style data lines
plot 'data.txt' using 1:2, '' using 1:3, '' using 1:4

Since version 4.4 you can use iterations inside the plot command:

set key autotitle columnheader
set style data lines
plot for [i=2:4] 'data.txt' using 1:i

Instead of using the set key autotitle columnheader you can also use title columnheader or title columnheader(i+1) if the title column doesn't match the column given in the using statement. This also works at least since 4.2.