gpt4 book ai didi

graphics - 如何使用 GNUPlot 根据列中的值绘制单/多行

转载 作者:行者123 更新时间:2023-12-05 01:03:45 24 4
gpt4 key购买 nike

我在使用 gnuplot 时遇到了一些问题。这是我的数据文件:

From Time Packets Jitter  
127.0.0.1:53091 1 0 274
127.0.0.1:53091 2 0 417
127.0.0.1:53091 3 36 53
127.0.0.1:53091 4 215 55
127.0.0.1:53090 4 215 55
127.0.0.1:53091 5 215 33
127.0.0.1:53090 6 256 78

(我把那个“时间”放在测试中,但它会在它工作后被一个日期时间取代)

我想画两个不同的图形,用 Time x 轴上的列,以及 Packets y 轴上的列(在第一个图形上)和抖动列(在第二个图形上)。但是,正如您可能已经看到的,我不知道 From 中有多少不同的值。我将拥有的列(最少 1,但我不知道最大值,数据文件将被刷新,并且每 x 秒将添加一些值)。
所以我的问题是我想制作另一条不同的“线” From两个图形上的值。
事实上,拥有 From行标题中的值(例如:“127.0.0.1:53091”)。
如果可以更改列顺序,我想补充一点。

我试过:
plot 'data.log' using 3:xtic(2) title 'Packets' with lines, \
'data.log' using 4:xtic(2) title 'Jitter' with lines

但它在同一个图形上(我还没有使用 multiplot,我之前尝试使多条线起作用)。

是否可以 ?如果是,我如何在 gnuplot 中绘制这两个图形?
如果没有,我们可以删除 Jitter图形,并仅绘制 Packets单个图形上的列,但具有不同的 From值。

最佳答案

这是一个不需要外部文件的解决方案。首先,我提取第一列中的所有不同来源并将它们存储在一个 gnuplot 变量中:

filename = 'data.log'
from=system('tail -n +2 '.filename. '| cut -f 1 -d " " | sort | uniq')

对于绘图期间的过滤,我使用 awk并定义一个 gnuplot 函数
select_source(w) = sprintf('< awk ''{if ($1 == "%s") print }'' %s', w, filename)

现在您可以遍历存储在 from 中的所有源.完整的 gnuplot 脚本如下:
filename = 'data.log'
from=system('tail -n +2 '.filename. '| cut -f 1 -d " " | sort | uniq')
select_source(w) = sprintf('< awk ''{if ($1 == "%s") print }'' %s', w, filename)

set style data linespoints
set multiplot layout 1,2

set title 'Packets'
plot for [f in from] select_source(f) using 2:3 title f

set title 'Jitter'
plot for [f in from] select_source(f) using 2:4 title f

unset multiplot

enter image description here

关于graphics - 如何使用 GNUPlot 根据列中的值绘制单/多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24325128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com