Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot smooth confidence band

According to the answer given in this question Gnuplot smooth confidence interval lines as opposed to error bars I was able to get the same result for my data given by (the error of y is symmetric so it is y plus/minus errorY):

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

Code:

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

Now the confidence band is given by connecting every y+errorY and y-errorY point. I would like it if the connection is not just a straight line, but rather a smooth line, like how one can smoothen data points with smooth csplines..

like image 916
nerdizzle Avatar asked May 24 '15 19:05

nerdizzle


1 Answers

That is a bit tricky, because smoothing works only on a single column, and can't be directly combined with the filledcurves plotting style.

So you must first generate two temporary data files by plotting the smoothed upper and lower confidence boundaries to separate data files with

set table 'lower.dat'
plot 'data.dat' using 1:($2-$3) smooth cspline
set table 'upper.dat'
plot 'data.dat' using 1:($2+$3) smooth cspline
unset table

And then combining those two files with paste lower.data upper.dat before plotting the data. If you don't have the paste command line program, you can also use any other script like paste.py to merge the files:

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'

enter image description here

like image 143
Christoph Avatar answered Nov 15 '22 08:11

Christoph