Gnuplot columnstacked histogram-行/行计数

Gnuplot columnstacked histogram-行/行计数,gnuplot,histogram,Gnuplot,Histogram,我有一个数据文件,其条目数未定义,如下所示: A B C D E.. 1 0 2 5 4 7 4 3 4 1 8 7 4 0 7 1 1 rows = `awk 'END {print NR}' data.log` columns = `awk '{if(NR == 1) print NF}' data.log` print "The maximum number of rows is ", rows, " and the maximum number of columns is

我有一个数据文件,其条目数未定义,如下所示:

A B C D E..
1 0 2 5 4
7 4 3 4 1
8   7 4 0
7     1 1
rows = `awk 'END {print NR}' data.log`
columns = `awk '{if(NR == 1) print NF}' data.log`
print "The maximum number of rows is ", rows, " and the maximum number of columns is ", columns
plot for [i=1:columns] 'data.log' using i notitle
第一行代表工作时间,而不是以交替方式暂停等。为了使这一点可视化,我通过定义两种不同颜色的线型并通过以下方式绘制柱状图:

plot for [i=1:10] 'data.log' using i notitle
但问题是:我必须猜测I的最大值。如何获取数据文件的列数? 定义交替线型时,我需要估计最大线数,以便覆盖使用类似for循环的默认线型:

set for [j = 1:1000:2] style line i lc rgb "white"
set for [j = 2:1000:2] style line i lc rgb "red"
这里,我需要将数据中某列的最大行数设置为j的最大值

有没有办法获取这些值?可能只使用gnuplot的内置特性(因为我不熟悉awk脚本)

谢谢你的阅读, 致意


备注:我使用的是Windows,您可以如下方式确定数据文件的列数和行数:

A B C D E..
1 0 2 5 4
7 4 3 4 1
8   7 4 0
7     1 1
rows = `awk 'END {print NR}' data.log`
columns = `awk '{if(NR == 1) print NF}' data.log`
print "The maximum number of rows is ", rows, " and the maximum number of columns is ", columns
plot for [i=1:columns] 'data.log' using i notitle
通过这种方法,您无需使用
awk
即可获得相同的结果

rows = `cat data.log | wc -l`
columns = `head data.log -n1 | wc -w`

谢谢,更新了帖子。有没有不使用awk脚本的解决方案?如果我能避免的话,我不想再挖awk了。好吧,我明白了。您建议保留gnuplot脚本并运行一些linux命令。我的错我没说我在Windows电脑上。如何在gnuplot功能中实现这一点?抱歉,AFAIK gnuplot不支持此功能。部分答案: