我有一个数据文件,其中包含未定义数量的条目,如下所示:
A B C D E..
1 0 2 5 4
7 4 3 4 1
8 7 4 0
7 1 1
第一行代表工作时间,然后以交替的方式暂停等等。为了可视化这一点,我通过定义两种具有不同颜色的线条样式并通过以下方式绘制它来绘制柱状直方图:
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 脚本)。
谢谢阅读,
此致
PS:我用的是Windows
您可以像这样确定数据文件的列数和行数:
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`
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)