2017-03-17 331 views
1

[現在]gnuplotの中の点の平均曲線をプロット

Iは最初の列は、シミュレーション時間を(0〜150)は、第2の列は、遅延(〜0.02 0.01)を有し有しているテキストファイルをインポートしています。

私にプロットできます
1.000000 0.010007 
1.000000 0.010010 
2.000000 0.010013 
2.000000 0.010016 
. 
. 
. 
149.000000 0.010045 
149.000000 0.010048 
150.000000 0.010052 
150.000000 0.010055 

Instantanous Delay in Seconds


を[希望]

私は赤い線と、次の図に示すように、その上に平均線をプロットする必要があります。

Average red line

答えて

1

編集

更新された質問は約moving averageです。

これは、this demoに従って、gnuplotだけで限定的に行うことができます。

私の意見では、pythonまたはrubyのようなプログラミング言語を使用してデータを前処理し、必要な移動平均の余分な列を追加する方が柔軟性があります。

オリジナルの答えは以下に保存されて:あなたはfitを使用することができます


。あなたは一定の機能に合わせたいと思うようです。このように:

f(x) = c 

fit f(x) 'S1_delay_120_LT100_LU15_MU5.txt' using 1:2 every 5 via c 

これらの両方をプロットすることができます。

plot 'S1_delay_120_LT100_LU15_MU5.txt' using 1:2 every 5, \ 
f(x) with lines 

このテクニックは、定数またはラインエア関数だけでなく、任意の関数で使用できます。ここで

+0

私は親切に一見を更新しました – saif

1

は、サンプルデータと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 

これは結果である:

moving average

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