Gnuplot 列堆叠直方图 - 行/行计数

发布于 2025-01-06 07:37:56 字数 630 浏览 1 评论 0原文

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

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"

这里我需要将数据中的列的最大行数设置为 max j 的值。

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

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

PS:我使用的是 Windows

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

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"

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

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: I'm using Windows

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2025-01-13 07:37:56

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

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`

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

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`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文