Gnuplot列堆叠直方图-行/行数 [英] Gnuplot columnstacked histogram - line/row count

查看:92
本文介绍了Gnuplot列堆叠直方图-行/行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a data file with an undefined number of entries that looks like this:

A B C D E..
1 0 2 5 4
7 4 3 4 1
8   7 4 0
7     1 1

第一行表示工作时间,而不是暂停,依此类推.为了可视化,我通过定义两种具有不同颜色的线型并通过以下方式对其进行绘制来绘制其上的柱状堆叠直方图:

First row represents working time, than pause and so on in alternating fashion. To visualise this, I plot a columnstacked histograms from it by defining two linestyles with different colours and plotting it via:

plot for [i=1:10] 'data.log' using i notitle

但是问题是:我必须猜测i的最大值.如何获取数据文件的列数? 在定义交替的线型时,我需要估计最大行数,以便覆盖我使用类似的for循环的默认线型:

But the problem is: I have to guess the max value of i. How can I get the number of columns the data file has? And when defining the alternating linestyles I need to estimate the max number of lines in order to overwrite the default linestyles for what i use a similar for-loop:

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的最大值.

Here I need to set the max number lines a column in my data has as the max value for j.

是否有办法获取这些值?可能仅使用gnuplot的内置功能(因为我对awk脚本不熟悉).

Is there a way to grab these values? Possibly by using built-in features of gnuplot only (for I am not familiar with awk scripting).

感谢您的阅读, 最好的问候

Thanks for reading, best regards

PS:我正在使用Windows

PS: I'm using Windows

推荐答案

您可以像这样确定数据文件的列数和行数:

You can determine the number of columns and rows of your datafile like this:

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即可获得相同的结果

You can achieve the same result without using awk with this approach

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

这篇关于Gnuplot列堆叠直方图-行/行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆