Šimon Tóth
Šimon Tóth

Reputation: 36433

Gnuplot - plotting labeled line data

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?

Upvotes: 2

Views: 431

Answers (1)

Christoph
Christoph

Reputation: 48390

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.

Upvotes: 2

Related Questions