gnuplot 中的自动系列?

Automatic series in gnuplot?

我有这样的输入:

year   s1   s2  s3
2000   1    2   3 
2001   2    4   6 
2002   4    8   12

不知道有多少个系列。今天是3,明天可能是4。

我想在多系列图表中绘制它。像这样:

set key autotitle columnhead
plot 'data/chart-year-subreddit-count' using 1:2 with lines, \
'data/chart-year-subreddit-count' using 1:3 with lines, \
'data/chart-year-subreddit-count' using 1:4 with lines

除非我不知道有多少列,否则我不知道要在我的 gnuplot 脚本中放入什么。

写文件一定要写脚本吗?或者 gnuplot 可以自动计算出有多少个系列吗?

Gnuplot 本身无法计算列数,但您可以使用例如wchead 来计算列数:

file = 'data/chart-year-subreddit-count'
cols = int(system('head -1 '.file.' | wc -w'))
plot for [i=2:cols] file using 1:i with lines