2
votes

I have this big file:

label1 value1 value2 ... valuen
.
.
.
labeln value1 value2 ... valuen

I want to plot this as standard line plot, where the lines will be labeled using the first column. Can this be done in gnuplot? Specifically, is it possible, without explicitly stating each of the lines in the plot script?

1
So you want the values to be plotted against the respective column number, each row is one line and the first column is the legend entry for that line? This format is not directly supported by gnuplot. If you would transpose your data file, you could use title columnheader for this. - Christoph
@Christoph I could transpose the data, what is supported format? - Šimon Tóth
I added an answer assuming your data file has a different format (rows and columns exchanged). - Christoph

1 Answers

2
votes

If you have transposed data compared to your current format, i.e. a file like

label1 label2 ... labeln
value1 value1 ... value1
.
.
.
valuen valuen ... valuen

you can simply use title columnheader to use the string in the first row as legend (key) label:

N = 3 # number of columns
plot for [i=1:N] 'file.dat' using 0:i title columnheader

That uses the row number (column 0) as x-value.

If you don't know the number of columns beforehand, you could use e.g.

N = int(system("awk 'NR == 2 { print NF; exit }' file.dat"))

to calculate it.