は、サンプルデータとgnuplotの唯一のソリューションです:
set table "test.data"
set samples 1000
plot rand(0)+sin(x)
unset table
あなたは移動平均ためgnuplot demoページをチェックしてください。関数を動的に構築するという観点から、このデモを一般化するつもりです。これにより、平均点に含まれる点の数を変えることがずっと簡単になります。
これはスクリプトである:
# number of points in moving average
n = 50
# initialize the variables
do for [i=1:n] {
eval(sprintf("back%d=0", i))
}
# build shift function (back_n = back_n-1, ..., back1=x)
shift = "("
do for [i=n:2:-1] {
shift = sprintf("%sback%d = back%d, ", shift, i, i-1)
}
shift = shift."back1 = x)"
# uncomment the next line for a check
# print shift
# build sum function (back1 + ... + backn)
sum = "(back1"
do for [i=2:n] {
sum = sprintf("%s+back%d", sum, i)
}
sum = sum.")"
# uncomment the next line for a check
# print sum
# define the functions like in the gnuplot demo
# use macro expansion for turning the strings into real functions
samples(x) = $0 > (n-1) ? n : ($0+1)
avg_n(x) = (shift_n(x), @sum/samples($0))
shift_n(x) = @shift
# the final plot command looks quite simple
set terminal pngcairo
set output "moving_average.png"
plot "test.data" using 1:2 w l notitle, \
"test.data" using 1:(avg_n($2)) w l lc rgb "red" lw 3 title "avg\\_".n
これは結果である:

アルゴリズムから予想されるように平均はかなりデータポイントより遅れます。たぶん50ポイントが多すぎます。あるいは、中心移動平均の実装について考えることもできますが、これはこの質問の範囲を超えています。 また、私はあなたが外部プログラムでより柔軟性があるとも思っています:)
私は親切に一見を更新しました – saif