Gnuplot累积栏问题

时间:2009-11-13 18:01:14

标签: plot gnuplot

我有一些数据。

#Time  Distance
 1   3
 2   5
 4   9
 8  11
12  17
14  20
16  34
20  40

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

X

6 个答案:

答案 0 :(得分:25)

对于仍在寻找此类事物的人,如果您的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))

答案 1 :(得分:14)

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

$ gnuplot
gnuplot> plot "datafile" smooth cumulative

答案 2 :(得分:6)

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

plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines

答案 3 :(得分:6)

同样可以通过“smooth”选项的“累积”变体实现(只需在gnuplot中输入help smooth)。

答案 4 :(得分:1)

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

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

答案 5 :(得分:1)

这不是问题所在,但“gnuplot累积分布函数”总是引导我到这里,除非你已经有gnuplot预期的数据,否则没有一个答案是正确的。

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

test.dat

#Time  Distance
 1   3
 2   5
 4   9
 8  11
12  17
14  20
16  34
20  40

plot.gpi

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

enter image description here

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