Reading gnuplot legend from csv

后端 未结 1 1310
鱼传尺愫
鱼传尺愫 2021-02-09 19:56

I\'ve got a data.csv file which is structured like this:

n    John Smith stats     Sam Williams stats
1                23.4                   44.1
2                      


        
1条回答
  •  粉色の甜心
    2021-02-09 20:37

    You say you have a csv file, so I assume your data file looks like this (and is saved in infile.csv):

    n,John Smith stats,Sam Williams stats
    1,23.4,44.1
    2,32.1,33.5
    3,42.0,42.1
    

    If your version of Gnuplot is recent enough, you can use columnhead as the title argument:

    echo "
      set datafile separator ','
      plot 'infile.csv' using 1:2 with lines title columnhead
    " | gnuplot --persist
    

    Or use the key option:

    echo "
      set datafile separator ','
      set key autotitle columnhead
      plot 'infile.csv' using 1:2 with lines, '' using 1:3 with lines
    " | gnuplot --persist
    

    Edit - shorten headings

    echo "
      set datafile separator ','
      set key autotitle columnhead
      plot '< sed -r \"1 s/,([^ ]+)[^,]+/,\1/g\" infile.csv' using 1:2 with lines, '' using 1:3 with lines
    " | gnuplot --persist
    

    Output:

    Plot of column 1:2 and 1:3 of infile.csv

    Note this answer to a follow-up question may also be relevant.

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