绘制gnuplot中的标准化直方图

时间:2017-11-23 12:06:56

标签: gnuplot histogram

我的dropbox提供了一组数据(一列)。在Dropbox中,还有一个gnuplot代码,可生成以下数字: Not normalized histogram for velocitiesNot normalized distribution for the radius。我想做的是以下

  1. 使用gnuplot
  2. 标准化两个直方图
  3. 使半径图与速度一样好,并尽可能放大两者。
  4. 我因为一周没有使用gnuplot中的直方图而面对这个问题,所以非常感谢你的帮助。这是gnuplot代码:

    reset
    set terminal pngcairo 
    set output 'r_distr_3ev.png'
    set key off
    set border 3
    
    set boxwidth 0.05 absolute
    set style fill solid 1.0 noborder
    
    bin_width = 0.005;
    
    bin_number(x) = floor(x/bin_width)
    
    rounded(x) = bin_width * ( bin_number(x) + 0.00025 )
    
    plot 'data_prob_distr_funct_radius_3eV.dat' using (rounded($1)):(1) 
    smooth frequency with boxes
    
    
    reset
    set terminal pngcairo 
    set output 'v_distr_3ev.png'
    set key off
    set border 3
    
    set boxwidth 0.05 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 )
    
    plot 'data_prob_distr_funct_veloci_3eV.dat' using (rounded($3)):(1) 
    smooth frequency with boxes
    

    以下是数据样本(文件太长,无法完全发布)。但是,需要在绘图命令上编辑数据源。

     # radius                        # Velocities
    1.432710516747764062         0.518383911504932460
    1.415400787912409752         0.117744310428800222
    1.420463215076467778         0.083766261830559782
    1.437922410272506557         0.309560054349534541
    1.420463215076467778         0.268622745024368170
    1.438756837417662471         0.203390900905284472
    1.418356121124933145         0.518346867895466801
    1.438756837417662471         0.182812150806309304
    1.421657988632006209         0.299301056216330852
    1.432074613018175180         0.293967535681474712
    1.421657988632006209         0.183613746565735064
    1.412588932829508259         0.501168210407462289
    1.416512172894701438         0.179507944624779481
    1.412588932829508259         0.029653108171494944
    1.417995684224648612         0.234379565912604448
    1.417914885270917580         0.255589209064060963
    1.417995684224648612         0.539792616529789826
    1.408834060670934862         0.256331796703176962
    1.423042784959195561         0.082132902455306064
    1.408834060670934862         0.198595146234998993
    1.432298354037856436         0.255681807316227472
    1.406168218647184665         0.595524682621352608
    1.432298354037856436         0.150127810412636647
    1.431591815111461719         0.271379130577297567
    1.422276604689641788         0.367863070449541862
    1.431591815111461719         0.135432525011420862
    1.431551259009345989         0.138525547190355175
    1.400408991855918162         0.626963309755715237
    1.431551259009345989         0.294435076616490321
    1.425580611910310047         0.527847978352356417
    

    干杯

1 个答案:

答案 0 :(得分:0)

要获得标准化的直方图,您需要按比例增加每个数据点的计数。这转化为:

plot 'file.dat' u (rounded($1)):(1./(sum*bin_width)) smooth freq w boxes

其中sum是数据条目的数量。如果您已经从程序中了解sum,那么您可以这样理解:

stats file.dat
sum=floor(STATS_records/100.)

要使两个直方图看起来相同(不错),请将boxwidthbin_width设置为相同的值。