GNUPlot - 堆积线中的任意列数

GNUPlot - Arbitrary number of columns in stacked line

我正在编写一个脚本,该脚本针对给定的 x 值生成具有任意数量的 y 值的 csv。 csv 的第一行包含数据集的名称。 x 值是一个 unix 时间戳。我想使用 gnuplot 将此数据绘制为堆叠折线图,其中值显示为该行总数的分数。我该怎么做?

我查看了以下解决方案,并尝试将它们集成,但我无法弄清楚我做错了什么。

它会说列数不够或列数不匹配。

给定时间索引最多有 N 列数据。我正在查看的总数是针对给定时间索引的。

--

我的数据示例:

KEY,CSS,JavaScript,Perl,Python,Shell
1428852630,0,0,0,0,406
1428852721,0,0,0,0,406
1428852793,0,0,0,0,406
1428853776,0,0,0,0,781
1429889154,0,0,0,0,1200
1429891056,0,0,0,0,1648
1429891182,0,0,0,0,1648
1429891642,0,0,0,0,1648
1430176065,0,0,0,0,2056

但是,可能会有大量的列,我想要一个在 运行 时间设置列数的列。


http://gnuplot.sourceforge.net/demo/histograms.html - 这似乎与被修改为具有任意数量的列有关。

plot 'immigration.dat' using (100.*/):xtic(1) t column(2), \
    for [i=3:23] '' using (100.*column(i)/column(24)) title column(i)

https://newspaint.wordpress.com/2013/09/11/creating-a-filled-stack-graph-in-gnuplot/

This answer 显示如何对列进行计数,稍作修改:

file="file.dat"
get_number_of_cols = "awk -F, 'NR == 1 { print NF; exit }' ".file
nc=system(get_number_of_cols)

然后你需要将列 2 求和到 nc,让我们用递归来完成:

sum(c,C)=((c!=C)?column(c)+sum(c+1,C):column(c))

现在你可以绘制了:

set key outside
set datafile separator ","
plot for [i=nc:2:-1] file using 0:(100*sum(2,i)/sum(2,nc)):xtic(1) title columnhead(i) with filledcurve y=0