在 Gnuplot 的 for 循环中拟合多条数据
Fit many pieces of data in Gnuplot's for loop
数据
Model Decreasing-err Constant-err Increasing-err
2025 73-78 80-85 87-92
2035 63-68 80-85 97-107
2050 42-57 75-90 104.5-119.5
哪个数据结构(使用 -err)描述了 。
为了绘制点,我 运行
set terminal qt size 560,270;
set grid; set offset 1,1,0,0;
set datafile separator " -";
set key autotitle columnhead;
plot for [i=2:6:2] "data.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror;
并得到
但是,我想在这些点上添加一条线,由于问题,您不能只用 with yerrorlines
做。
我的拟合增减线的伪代码
inc(x) = k1*x + k2;
con(x) = n1*x + n2;
dec(x) = m1*x + m2;
fit inc(x), con(x) dec(x) for [i=2:6:2] "data.dat"
using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i)))
via k1,k2,n1,n2,m1,m2;
问题在于将函数 fit
与 for 循环一起使用。
如何在 for 循环中使用 Gnuplot 的拟合?
我想同时将多行拟合到数据中。
我会结合使用 do
和 eval
来做到这一点:
# Define your functions (you can also use do + eval to do this)
f1(x) = a1*x+b1
f2(x) = a2*x+b2
f3(x) = a3*x+b3
# Loop
do for [i=1:3] {
eval sprintf("fit f%g(x) 'data.dat' u 0:%g via a%g, b%g", i, i, i, i)
}
您可以根据自己的目的调整以上内容。
数据
Model Decreasing-err Constant-err Increasing-err
2025 73-78 80-85 87-92
2035 63-68 80-85 97-107
2050 42-57 75-90 104.5-119.5
哪个数据结构(使用 -err)描述了
为了绘制点,我 运行
set terminal qt size 560,270;
set grid; set offset 1,1,0,0;
set datafile separator " -";
set key autotitle columnhead;
plot for [i=2:6:2] "data.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror;
并得到
但是,我想在这些点上添加一条线,由于问题,您不能只用 with yerrorlines
做。
我的拟合增减线的伪代码
inc(x) = k1*x + k2;
con(x) = n1*x + n2;
dec(x) = m1*x + m2;
fit inc(x), con(x) dec(x) for [i=2:6:2] "data.dat"
using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i)))
via k1,k2,n1,n2,m1,m2;
问题在于将函数 fit
与 for 循环一起使用。
如何在 for 循环中使用 Gnuplot 的拟合? 我想同时将多行拟合到数据中。
我会结合使用 do
和 eval
来做到这一点:
# Define your functions (you can also use do + eval to do this)
f1(x) = a1*x+b1
f2(x) = a2*x+b2
f3(x) = a3*x+b3
# Loop
do for [i=1:3] {
eval sprintf("fit f%g(x) 'data.dat' u 0:%g via a%g, b%g", i, i, i, i)
}
您可以根据自己的目的调整以上内容。