9

I'd like a 95% confidence interval line above and below my data line - as opposed to vertical bars at each point.

Is there a way that I can do this in gnuplot without plotting another line? Or do I need to plot another line and then label it appropriately?

Charon
  • 2,344
  • 6
  • 25
  • 44

2 Answers2

13

You can use the filledcurves style to fill the region of 95% confidence. Consider the example data file data.dat with the content:

# x y   ylow yhigh
1   3   2.6  3.5
2   5   4    6
3   4   3.2  4.3
4   3.5 3.3  3.7

and plot this with the script

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

to get

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • I'd like to do the same, but in my rows I saved only x,y,error of y. the error is symmetric, y =y \pm error y. now my question how can I use in the plot something like 1:(2-3):(2+3)? – nerdizzle May 24 '15 at 13:35
  • @Christoph sorry, I should've been more explicit, I don't know how to access the column in each row and subtract and add the error. I used: 1:&(2-3):&(2+3) and 1:(&2-&3):(&2+&3), but this does not work – nerdizzle May 24 '15 at 13:44
  • 1
    `using 1:($2-$3):($2+$3)` – Christoph May 24 '15 at 13:46
  • thank you. but there very thin white lines at each point where the errorbar would've been. how would one smoothen the filled curve? – nerdizzle May 24 '15 at 13:51
  • These are only artifacts from your PDF viewer, where two adjacent polygons touch each other – Christoph May 24 '15 at 14:28
  • Ok, thanks. But is does't work well with the smooth command, which would be nice somehow – nerdizzle May 24 '15 at 18:47
  • You must probably write the smoothed data to a temporary file and then plot this with filledcurves. In any case, this discussion is getting pretty long. Please post a separate question with some data samples and explaining what you all want, what you have currently and what doesn't work – Christoph May 24 '15 at 18:56
0

To plot the data, with the mean and the standard deviation as error bars.

Save the below code as example.gnuplot

set terminal pdf size 6, 4.5 enhanced font "Times-New-Roman,20"
set output 'out.pdf'
red = "#CC0000"; green = "#4C9900"; blue = "#6A5ACD"; skyblue = "#87CEEB"; violet = "#FF00FF"; brown = "#D2691E";
set xrange [0:*] nowriteback;
set yrange [0.0: 10.0]
set title "Line graph with confidence interval"
set xlabel "X Axis"
set ylabel "Y Axis"
plot "data.dat" using 1:2:3 title "l1" with yerrorlines lw 3 lc rgb red,\
        ''using 1:4:5 title "l2" with yerrorlines lw 3 lc rgb brown

Create a new file called "data.dat" and give some sample values, such as

X  Y  Stddev    y1  std
1   2  0.5  3   0.25
2   4  0.2  5   0.3
3   3  0.3  4   0.35
4   5  0.1  6   0.3
5   6  0.2  7   0.25

Run the script using the command gnuplot example.gnuplot