我有一些数据.
#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)
dpa*_*tru 14
如果您的数据在文件数据文件中,您可以执行如下累积绘图:
$ gnuplot
gnuplot> plot "datafile" smooth cumulative
Run Code Online (Sandbox Code Playgroud)
假设您的数据位于文件"test.txt"中,那么:
plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines
Run Code Online (Sandbox Code Playgroud)
这不是问题所要寻找的,但“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)
但它并不像拥有所有数据那么灵活。