Gnuplot 平滑置信带

Gnuplot smooth confidence band

根据这个问题 Gnuplot smooth confidence interval lines as opposed to error bars 给出的答案,我的数据得到了相同的结果(y 的误差是对称的,所以它是 y plus/minus errorY):

# x y errorY   
1   3   0.6 
2   5   0.4  
3   4   0.2
4   3.5 0.3

代码:

set style fill transparent solid 0.2 noborder
plot 'data.dat' using 1:(-):(+) with filledcurves title '95% confidence', \
     '' using 1:2 with lp lt 1 pt 7 ps 1.5 lw 3 title 'mean value'

现在通过连接每个 y+errorY 和 y-errorY 点给出置信带。如果连接不仅仅是一条直线,而是一条平滑的线,我会喜欢它,比如如何使用 smooth csplines..

平滑数据点

这有点棘手,因为平滑仅适用于单个列,不能直接与 filledcurves 绘图样式结合使用。

所以你必须首先生成两个临时数据文件,方法是绘制平滑的上下置信边界,用

分隔数据文件
set table 'lower.dat'
plot 'data.dat' using 1:(-) smooth cspline
set table 'upper.dat'
plot 'data.dat' using 1:(+) smooth cspline
unset table

然后在绘制数据之前将这两个文件与 paste lower.data upper.dat 合并。如果您没有 paste 命令行程序,您也可以使用任何其他脚本,例如 paste.py 来合并文件:

set terminal pngcairo
set output 'data.png'

set style fill transparent solid 0.2 noborder
plot '< paste lower.dat upper.dat' using 1:2:5 with filledcurves title '95% confidence', \
     'data.dat' using 1:2 with lines lt 1 smooth cspline title 'mean value',\
     '' using 1:2 with points lt 1 pt 7 ps 1.5 lw 3 title 'data points'