Search code examples
gnuploterrorbar

Automatic computation of errorbars in gnuplot


I know that errorbars or candlebars with whiskerbars can be plotted by gnuplot by giving it mean, max, min, deviation...

Is there a way how to compute these automatically? I have got a file, each line should be one errorbar, first column is x, another eleven columns are distinct measurements of some f(x).


Solution

  • I will show how to plot error bars representing +/- sigma. You can adjust the formulae to suit if you want error bars representing unbiased standard error or min/max or something else.

    # N is the number of data columns, i.e. columns 2 through N+1
    sumx(N) = sum [i=2:N+1] column(i)
    sumx2(N) = sum [i=2:N+1] column(i) * column(i)
    
    mean(N) = sumx(N) / N
    sigma(N) = sqrt( sumx2(N)/N - (sumx(N)/N)**2 )
    
    N=11
    plot 'datafile' using (column(1)) : (mean(N)) : (sigma(N)) with yerrorbars