如何在直方图中创建更少的箱

时间:2018-11-06 06:55:57

标签: gnuplot histogram

如何在gnuplot的直方图中设置较少的bin?

以下是此直方图的http://leteckaposta.cz/514785176数据。

谢谢

clear
reset
f(x)=a*exp((-(x-b)**2)/(2*c**2))
a=27.3634;
b=131.12;
c=11.0518;
set key off
set border 3
set yzeroaxis
set boxwidth 0.3 absolute
set style fill solid 1.0 noborder

bin_width = 0.1;

bin_number(x) = floor(x/bin_width)

rounded(x) = bin_width * ( bin_number(x) + 0.5 )
set ytics nomirror font "Times New Roman,12"
set xtics nomirror font "Times New Roman,12"
set key top right font "Times New Roman,12"
set xlabel "Počet detekcí" font "Times New Roman,12"
set ylabel "Četnost" font "Times New Roman,12"
plot [95:175] 'poisson.txt' using (rounded($1)):(1) smooth frequency with boxes title "Naměřeno", f(x) title "Gaussova křivka" 

1 个答案:

答案 0 :(得分:0)

使用Philipp K Janert的书“ Gnuplot In Action”(第256f页)和this网络示例,我为您提供了以下解决方案(源文件中的注释):

f(x)=a*exp((-(x-b)**2)/(2*c**2))
a=27.3634;
b=131.12;
c=11.0518;

stats 'poisson.txt' nooutput        # produces statistics about the datafile
N = STATS_records                   # number of records in the file

set key off
set border 3
set yzeroaxis
set boxwidth 0.8 absolute           # set the width of your boxes
set style fill solid 1.0 noborder

bin_width = 2                       # controls the number of boxes / bins
bin(x, s) = s*int(x/s)              # normalising

set ytics nomirror font "Times New Roman,12"
set xtics nomirror font "Times New Roman,12"
set key top right font "Times New Roman,12"
set xlabel "Počet detekcí" font "Times New Roman,12"
set ylabel "Četnost" font "Times New Roman,12"
plot 'poisson.txt' u (bin($1,bin_width)):((N/2)/N) smooth freq title "Naměřeno" w boxes, f(x) title "Gaussova křivka"
                                   # ((N/2)/N) controls the height of your boxes

产生

enter image description here