14

我有一些数据。

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

我想在 gnuplot 中绘制累积距离 wrt 时间......(应该很容易)但我不知道如何。

X

4

6 回答 6

28

对于仍在寻找此类东西的任何人,如果您的 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))
于 2012-03-14T20:33:14.333 回答
16

如果您的数据在文件数据文件中,您可以像这样进行累积图:

$ gnuplot
gnuplot> plot "datafile" smooth cumulative
于 2013-06-05T16:12:18.687 回答
6

假设您的数据在文件“test.txt”中,如何:

plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines
于 2009-11-13T19:00:06.130 回答
6

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

于 2011-12-21T14:47:56.423 回答
4

这不是问题所要寻找的,但是“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"

在此处输入图像描述

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

于 2017-06-25T12:27:51.783 回答
1

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

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

于 2009-11-13T18:50:09.277 回答