Gnuplot累积列问题

发布于 2024-08-11 10:50:06 字数 173 浏览 5 评论 0原文

我有一些数据。

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

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

x

I have some data.

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

I want to plot the cumulative distance wrt time in gnuplot ... (it should be easy) but I do not know how.

x

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

扶醉桌前 2024-08-18 10:50:06

对于仍在寻找此类内容的任何人,如果您的 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))

For anyone still looking for this sort of thing, If your gnuplot version is 4.4 or newer, you can do the following:

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))
情丝乱 2024-08-18 10:50:06

如果您的数据位于文件数据文件中,您可以像这样绘制累积图:

$ gnuplot
gnuplot> plot "datafile" smooth cumulative

If your data is in the file datafile, you can do a cumulative plot like so:

$ gnuplot
gnuplot> plot "datafile" smooth cumulative
梦里兽 2024-08-18 10:50:06

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

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

Assuming your data is in a file "test.txt", how about:

plot "<awk '{i=i+$2; print $1,i}' test.txt" with lines
回忆那么伤 2024-08-18 10:50:06

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

The same can be achieved by the "cumulative" variant of the "smooth" option (just enter help smooth in gnuplot).

紧拥背影 2024-08-18 10:50:06

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

在此处输入图像描述

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

This isn't what the question is looking for but "gnuplot cumulative distribution function" always leads me here and none of the answers are quite right unless you already have the data gnuplot expects.

But suppose you wanted a cumulative distribution function of just distances and only have the raw distances. There is a little trick with which gnuplot can calculate the y values:

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

It is not as flexible as having all the data, though.

青柠芒果 2024-08-18 10:50:06

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

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

I have a little experience with Gnuplot and I just pored over the documentation some. Unfortunately, I wasn't able to find a solution for generating a cumulative sum as you're plotting.

I think what you'll need to do is to massage your data with another program before letting Gnuplot at it. awk is one program that comes to mind, it's practically built for fiddling with columnar data. You can integrate this process into the plotting process by following these instructions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文