我有一些数据。
#Time Distance
1 3
2 5
4 9
8 11
12 17
14 20
16 34
20 40
我想在 gnuplot 中绘制累积距离 wrt 时间......(应该很容易)但我不知道如何。
X
对于仍在寻找此类东西的任何人,如果您的 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))
如果您的数据在文件数据文件中,您可以像这样进行累积图:
$ gnuplot
gnuplot> plot "datafile" smooth cumulative
假设您的数据在文件“test.txt”中,如何:
plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines
同样可以通过“平滑”选项的“累积”变体来实现(只需输入help smooth
gnuplot)。
这不是问题所要寻找的,但是“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"
但是,它不像拥有所有数据那样灵活。