Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set axis label with column header in gnuplot?

My question is very simple. Suppose I have a datafile with column headers, like as follows

first second
1 1 
2 1
3 6
4 9

In gnuplot how do i make it so that the datafile is plotted using the column header as axis label? e.g. by calling

plot datafile using 1:2

i get the xaxis labeled first and the yaxis labeled second?

edit: I do know that I can use the column header as a key entry via set key auto title column head, however that's not quite what I'm looking for.

like image 640
Ferdinando Randisi Avatar asked Apr 18 '13 17:04

Ferdinando Randisi


2 Answers

To elaborate the suggestion of @andyras, here is how you can do it:

datafile = 'filename.txt'
firstrow = system('head -1 '.datafile)
set xlabel word(firstrow, 1)
set ylabel word(firstrow, 2)
plot datafile using 1:2

You must plot with the explicit using statement, otherwise gnuplot will complain about bad data on line 1.

like image 173
Christoph Avatar answered Dec 17 '22 13:12

Christoph


I don't think this feature is built in to gnuplot; you would probably have to use an awk-like utility to pull those labels out of a datafile.

You could try submitting a feature request on gnuplot's sourceforge site, and get feedback from the developers there.

like image 42
andyras Avatar answered Dec 17 '22 13:12

andyras