1

I would like to plot means and confidence interval with Gnuplot. My data has several samples with the same x value

21  27  4   12  20  100 50000   false   0.1 "DFSA"  2   205068  31.986
24  27  4   12  20  100 50000   false   0.1 "DFSA"  2   207798  32.49448
22  27  4   12  20  100 50000   false   0.1 "DFSA"  2   207499  32.60746
23  27  4   12  20  100 50000   false   0.1 "DFSA"  2   214065  33.17844
25  27  4   12  20  100 50000   false   0.1 "DFSA"  2   198386  31.4488
26  27  4   12  20  100 50000   false   0.1 "DFSA"  2   208307  32.77412
28  27  4   12  20  100 50000   false   0.1 "DFSA"  2   208669  32.77474
27  27  4   12  20  100 50000   false   0.1 "DFSA"  2   214324  33.16506
30  27  4   12  20  100 50000   false   0.1 "DFSA"  2   209924  32.77186
29  27  4   12  20  100 50000   false   0.1 "DFSA"  2   212959  33.3218
32  27  4   12  20  100 50000   false   0.2 "DFSA"  2   486241  64.3479
31  27  4   12  20  100 50000   false   0.2 "DFSA"  2   487487  64.65076
33  27  4   12  20  100 50000   false   0.2 "DFSA"  2   494703  65.06718
34  27  4   12  20  100 50000   false   0.2 "DFSA"  2   488164  64.77828
36  27  4   12  20  100 50000   false   0.2 "DFSA"  2   476513  63.3158
35  27  4   12  20  100 50000   false   0.2 "DFSA"  2   491005  65.02426
38  27  4   12  20  100 50000   false   0.2 "DFSA"  2   487454  64.44962
37  27  4   12  20  100 50000   false   0.2 "DFSA"  2   490494  65.06572
39  27  4   12  20  100 50000   false   0.2 "DFSA"  2   472081  63.31234
40  27  4   12  20  100 50000   false   0.2 "DFSA"  2   498294  65.02114

It has ten samples with column 9 = 0.1 and the same with value 0.2. I want to plot the mean of column 13 (last column) with the confidence interval and use Gnuplot yerrorlines, which need data in four columns x mean min max. The formula of min and max values uses the STATS_mean, STATS_ssd, and STATS_records of column 13 with equal value in column 9.

I have tried to write the values x mean min max in a file with this

system("touch lbt.dat")
stats "data.txt" u ($9==0.1?$13:1/0) name "lbt01"
system("(0.1 lbt01_mean (lbt01_mean - 2.262*lbt01_ssd/sqrt(lbt_records)) (lbt01_mean + 2.262*lbt01_ssd/sqrt(lbt_records))) >> lbt.dat")

but I get error in the last system command to save the values in the lbt.dat file. I have also tried

system("printf '%f\t\%f\t\%f\t\%f' 0.1 lbt01_mean (lbt01_mean - 2.262*lbt01_ssd/sqrt(lbt_records)) (lbt01_mean + 2.262*lbt01_ssd/sqrt(lbt_records))) >> lbt.dat ")

(2.262 is the value of the t-student pdf for 95% confidence interval and 9 degrees of freedom).

It looks like the results of stasts, e.g. lbt01_mean cannot be written in a file using system.

Besides, since the data file has samples for 0.1 to 1.7 in steps of 0.1 (column 9), I would like to ask if is there a way to short the Gnuplot script.

Regards

3

An easy way to print to a file from gnuplot is with the print command, after setting the file with set print. Try

set print "lbt.dat"
print 0.1, lbt01_mean, \
  (lbt01_mean - 2.262*lbt01_ssd/sqrt(lbt01_records)),\
  (lbt01_mean + 2.262*lbt01_ssd/sqrt(lbt01_records))

In order to loop through all the values 0.1 to 1.7, you can use a for loop going from 1 to 17, then dividing by 10.

set print "lbt.dat"
do for [i=1:17] {
  v = i/10.
  stats "data.txt" u ($9==v?$13:1/0) name "A" nooutput
  print v, A_mean,   (A_mean - 2.262*A_ssd/sqrt(A_records)),\
    (A_mean + 2.262*A_ssd/sqrt(A_records))
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.