您的数据(我将文件命名为 'mas_data.txt')如下所示(请始终在您的问题中显示/提供相关数据)。
数据:(如何放大绘图)
### plotting data with zoom-in
reset session
FILE = 'mas_data.txt'
colX = 2
colY = 3
set key top left
set multiplot
plot FILE u colX:colY w lp pt 7 ps 0.3 lc rgb "red" ti "Data", \
set title "Zoom in"
set origin 0.45,0.1
set size 0.5, 0.6
set xrange [0:1.0]
plot FILE u colX:colY w lp pt 7 ps 0.3 lc rgb "red" ti "Data"
unset multiplot
### end of code
关于“最佳”拟合范围,您可以尝试以下步骤:
- 使用
stats 查找数据的绝对y 最小值(请参阅help stats)
- 将 x 范围从这个最小值限制到最大 x 值
- 与
f(x)=a*x+b 进行线性拟合并记住斜率的标准误差值(此处:a_err)
- 将 x 范围缩小 2 倍
- 回到 3. 直到达到迭代次数(这里:
N=10)
- 求
Aerr[i]的最小值,得到对应的x-range
假设如果相对误差 (Aerr[i]) 具有最小值,那么您将拥有从数据最小值开始的线性拟合的“最佳”拟合范围。
但是,我不确定此过程是否适用于您的所有数据集。也许有更聪明的程序。当然,您也可以在不同的步骤中减小 xrange。此过程可以作为进一步调整和优化的起点。
代码:
### finding "best" fitting range
reset session
FILE = 'mas_data.txt'
colX = 2
colY = 3
stats FILE u colX:colY nooutput # do some statistics
MinY = STATS_min_y # minimum y-value
MinX = STATS_pos_min_y # x position of minimum y-value
Xmax = STATS_max_x # maximum x-value
XRangeMax = Xmax-MinX
f(x,a,b) = a*x + b
set fit quiet nolog
N = 10
array A[N]
array B[N]
array Aerr[N]
array R[N]
set print $myRange
do for [i=1:N] {
XRange = XRangeMax/2**(i-1)
R[i] = MinX+XRange
fit [MinX:R[i]] f(x,a,b) FILE u colX:colY via a,b
A[i] = a
Aerr[i] = a_err/a*100 # asymptotic standard error in %
B[i] = b
print sprintf("% 9.3g % 9.3f %g",MinX,R[i],Aerr[i])
}
set print
print $myRange
set key bottom right
set xrange [0:1.5]
plot FILE u colX:colY w lp pt 7 ps 0.3 lc rgb "red" ti "Data", \
for [i=1:N] [MinX:R[i]] f(x,A[i],B[i]) w l lc i title sprintf("%.2f%%",Aerr[i])
stats [*:*] $myRange u 2:3 nooutput
print sprintf('"Best" fitting range %.3f to %.3f', MinX, STATS_pos_min_y)
### end of code
结果:
放大xrange[0:1.0]
0.198 19.773 1.03497
0.198 9.985 1.09066
0.198 5.092 1.42902
0.198 2.645 1.53509
0.198 1.421 1.81259
0.198 0.810 0.659631
0.198 0.504 0.738046
0.198 0.351 0.895321
0.198 0.274 2.72058
0.198 0.236 8.50502
"Best" fitting range 0.198 to 0.810