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

前端 未结 3 1656
深忆病人
深忆病人 2020-12-17 14:58

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

相关标签:
3条回答
  • 2020-12-17 15:30

    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.

    0 讨论(0)
  • 2020-12-17 15:35

    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.

    0 讨论(0)
  • 2020-12-17 15:35

    I think it is supported. You are just supposed to be able to use "":

    plot 'file' using "first":"second"

    Although, if you want to do math in your using specification, you'll need the column("") function, too

    plot 'file' using "first":(column("second")-(column("thrid"))

    (Using only quoted header names with the math didn't work for me, anyway.)

    0 讨论(0)
提交回复
热议问题