温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - gnuplot: plotting the average of columns with increment
gnuplot

其他 - gnuplot:以增量绘制列的平均值

发布于 2020-04-24 14:34:44

我有109列和3000行左右的数据。我想绘制直到x108的x1的平均值(忽略y和z),数据如下:

时间x1 y1 z1 x2 y2 z2 x3 y3 z4 ... x108 y108 z108

仅需几列就可以很好地工作,例如:

时间x1 y1 z1 x2 y2 z2 x3 y3 z3

用ls 4行绘制'file.dat'u 1:((($ 2 + $ 5 + $ 8)/ 3)

但是问题出在数据较大时,例如108列或更多。我不希望手动执行此操作,因为稍后数据会变大。

我努力了:

[i = 2:108:3]'file.dat'u 1:(column(i))的图,行ls 4

但是然后我会得到每种组合的图,这不是我想要的。那么,我怎样才能仅绘制x1 ... x108的平均值(忽略y和z)?

谢谢。

查看更多

提问者
joca
被浏览
47
theozh 2020-02-07 18:25

以下应该做您想要的。以下示例为平均值z1, ..., z3根据你的情况为平均的参数x1, ..., x108ColStart=2ColStep=3ColCount=108

同时检查help summation

码:

### average over several columns
reset session

$Data <<EOD
#n   x1   y1   z1   x2   y2   z2   x3   y3   z3
 1 1.11 1.21 1.31 2.11 2.21 2.31 3.11 3.21 3.31
 2 1.12 1.22 1.32 2.12 2.22 2.32 3.12 3.22 3.32
 3 1.13 1.23 1.33 2.13 2.23 2.33 3.13 3.23 3.33
 4 1.14 1.24 1.34 2.14 2.24 2.34 3.14 3.24 3.34
 5 1.15 1.25 1.35 2.15 2.25 2.35 3.15 3.25 3.35
 6 1.16 1.26 1.36 2.16 2.26 2.36 3.16 3.26 3.36
 7 1.17 1.27 1.37 2.17 2.27 2.37 3.17 3.27 3.37
 8 1.18 1.28 1.38 2.18 2.28 2.38 3.18 3.28 3.38
 9 1.19 1.29 1.39 2.19 2.29 2.39 3.19 3.29 3.39
EOD

ColStart = 4
ColStep = 3   
ColCount = 3

plot $Data u 1:((sum[i=0:ColCount-1] column(i*ColStep+ColStart))/ColCount) w lp pt 7 notitle
### end of code

结果:

在此处输入图片说明