2011-08-11 69 views
2

can gnuplot可以从原始数据文件创建boxplot?我知道如何从已经计算好的中位数,四分位数等like this中绘制箱形图 - 但是如何从原始数据文件?gnuplot:从原始数据创建boxplot

在原始数据文件的每一行中都有一个测试结果。

回答

0

如果我正确理解你的问题,你正在寻找一种方式来计算平均值,你可以做这样的事情:

calc_mean(x1,x2,x3) = (x1+x2+x3)/3 
calc_sum(x1,x2,x3) = x1+x2+x3 
get_min(x1,x2,x3) = x1 < x2 ? (x1 < x3 ? x1 : (x2 < x3 ? x2 : x3)) : (x2 < x3 ? x2 : x3) 
get_max(x1,x2,x3) = x1 > x2 ? (x1 > x3 ? x1 : (x2 > x3 ? x2 : x3)) : (x2 > x3 ? x2 : x3) 

plot "Data.csv" u 0:(calc_mean($1, $2, $3)) t "Mean" w l, \ 
     "" u 0:(calc_sum($1, $2, $3)) t "Sum" w l, \ 
     "" u 0:(get_min($1, $2, $3)) t "Min" w l, \ 
     "" u 0:(get_max($1, $2, $3)) t "Max" w l 

上面的脚本计算平均值,总和,最小和数据线的最大值。 using指令中的0只是将数据行的索引作为x坐标值。

用下面Data.csv

0.62614 0.50293 0.62078 
0.63789 0.58924 0.71288 
0.16297 0.77453 0.82417 
0.20703 0.22424 0.33596 
0.57829 0.96545 0.60737 

您将获得以下情节:

Plot of the script above

我希望这是你所期待的。

1

我想你必须最终使用外部程序来计算box plot的必要数据。我用过awk,但任何程序都可以在这个地方使用。请注意,我计算了每行原始数据中的开/关/最小/最大值,而不是均值和分位数。

set xrange [-1:9] 
plot "< awk '{sum=0; opening=$1; closing=$NF; min=$1; max=$1; \ 
       for (i=1; i<=NF; i++) {sum=sum+$i; if ($i<min) min=$i; if ($i>max) max=$i}; \ 
       print sum/NF, opening, closing, min, max}' \ 
     junk.dat" us 0:2:4:5:3 w candle notitle 

随着junk.dat文件中的以下数据:

5.532 5.040 4.962 19.314 5.136 
    10.004 4.592 5.836 6.999 7.823 
    8.887 6.335 5.545 5.056 6.216 
    4.341 4.552 4.512 4.009 5.811 
    4.724 4.869 5.016 2.593 5.662 
    4.555 5.472 4.866 5.559 -0.608 
    6.974 3.838 2.953 6.630 2.753 
    5.571 8.112 3.261 7.029 4.375 
    3.497 5.200 6.555 5.311 8.204 

这里的剧情,你会得到:

enter image description here