KcFnMi
KcFnMi

Reputation: 6161

Gnuplot set x y labels from column header (from file)

Considering the data (in file, test.txt):

i x(volts) y(amp)
0 1 5   
1 2 6   
2 3 7   
3 4 8   
4 5 3   
5 5 4 

If I do:

set key autotitle columnheader
plot "test.txt" using 1:2 

Then I get:

enter image description here

And, if I do:

set xlabel "x(volts)"
set ylabel "y(amp)"
plot "test.txt" using 1:2 

Then I get

enter image description here

In the first case I read the label from file but it went into the legend. In the second case I set the x y labels but not reading from file.

How do I set x y labels reading from file?

Upvotes: 1

Views: 1304

Answers (1)

Michael
Michael

Reputation: 5335

You can use system command to get output of the external program into variable.

s=system('head -n 1 test.txt')
set xlabel word(s,2)
set ylabel word(s,3)
plot 'test.txt' u 1:2

Upvotes: 2

Related Questions