0
votes

In GnuPlot, I can auto set a plot legend with title columnhead option in a plot command like:

plot 'test.txt' using 0:1 w linespoints title columnhead

So it reads the column name from the CSV file and use it in the legend.

enter image description here enter image description here

I would like the same to set xlabel and ylabel. Is is possible?

(Also, I'm interested in knowing how one will do such thing in Python. Is it better than GnuPlot? Should I learn Python instead?)

1
No, gnuplot doesn't support reading xlabel and ylabel from the data file. You would need to do it yourself with some shell command via system.Christoph

1 Answers

0
votes

as pointed out by @Christoph, the system command is probably the only viable solution - in your particular case, you could do:

fname="test.txt"

getTitle(colNum)=system(sprintf("head -n1 '%s' | cut -f%d -d';'", fname, colNum+1))

set xlabel getTitle(0)
set ylabel getTitle(1)