Gnuplot累积栏问题

Xof*_*ofo 13 plot gnuplot

我有一些数据.

#Time  Distance
 1   3
 2   5
 4   9
 8  11
12  17
14  20
16  34
20  40
Run Code Online (Sandbox Code Playgroud)

我想绘制gnuplot中的累计距离...(它应该很容易),但我不知道如何.

X

mgi*_*son 26

对于仍在寻找此类事物的人,如果你的gnuplot版本是4.4或更新版本,你可以执行以下操作:

a=0
#gnuplot 4.4+ functions are now defined as:  
#func(variable1,variable2...)=(statement1,statement2,...,return value)
cumulative_sum(x)=(a=a+x,a)
plot "test.dat" using 1:(cumulative_sum($2))
Run Code Online (Sandbox Code Playgroud)

  • @Thomas - 你确定你记得顶部的'a = 0`吗? (4认同)

dpa*_*tru 14

如果您的数据在文件数据文件中,您可以执行如下累积绘图:

$ gnuplot
gnuplot> plot "datafile" smooth cumulative
Run Code Online (Sandbox Code Playgroud)


Mar*_*ark 6

假设您的数据位于文件"test.txt"中,那么:

plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines
Run Code Online (Sandbox Code Playgroud)


小智 6

同样可以通过"平滑"选项的"累积"变体来实现(只需输入help smoothgnuplot).


mkj*_*sen 5

这不是问题所要寻找的,但“gnuplot 累积分布函数”总是引导我到这里,除非您已经拥有 gnuplot 期望的数据,否则没有一个答案是完全正确的。

但是假设您想要一个包含距离的累积分布函数并且只有原始距离。gnuplot 可以使用一个小技巧来计算这些y值:

test.dat

#Time  Distance
 1   3
 2   5
 4   9
 8  11
12  17
14  20
16  34
20  40
Run Code Online (Sandbox Code Playgroud)

plot.gpi

datafile = test.dat
stats datafile
plot datafile using 2:(1./STATS_records) smooth cumulative title "distance"
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但它并不像拥有所有数据那么灵活。


Car*_*icz 1

我对 Gnuplot 有一点经验,我只是仔细研究了一些文档。不幸的是,我无法找到在您绘制时生成累积和的解决方案。

我认为你需要做的是在让 Gnuplot 处理之前用另一个程序处理你的数据。awk是我想到的一个程序,它实际上是为摆弄柱状数据而构建的。您可以按照这些说明将此过程集成到绘图过程中。