【问题标题】:Normalized histograms in gnuplot with added function plotgnuplot 中的归一化直方图,添加了函数图
【发布时间】:2023-03-18 19:51:01
【问题描述】:

我有以下脚本来绘制直方图:

set terminal postscript eps enhanced color
set title "Histogram\_CreatesFile"

colour1="#00A0ff"
colour2="navy"
colour3="#ffA000"
colour4="#800000"
set output 'Histogram_CreatesFile.eps'
set yrange [0:]
set style fill solid 0.8 border -1
bin_width = 0.2
set boxwidth bin_width
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
plot 'Histogram_CreatesFile.txt' using (rounded($1)):(1) smooth frequency with boxes lc rgb colour1 notitle

这应该是一些分布的经验实现,所以为了更清楚,我想:

  1. 适当地标准化条形,以便将它们与密度函数进行比较(我猜条形面积的总和应该是统一的?这意味着每个条形的高度应该除以 barWidth* numberOfElements)
  2. 在同一张图片上绘制理论分布函数,由封闭形式公式(例如高斯)给出

我怎样才能做到这一点?

【问题讨论】:

    标签: gnuplot histogram


    【解决方案1】:

    我设法解决了这个问题。 (1)归一化进入冒号后面的列,所以plot命令变成:

    plot 'ConfUoMBM1validation0_0.txt' using (rounded($1)):(1/(bin_width*STATS_records)) smooth frequency with boxes lc rgb colour1 notitle
    

    (2) 函数的绘制再简单不过了,像往常一样在昏迷后进行

    所以最后的结果是:

    set terminal postscript eps enhanced color
    set title "ConfUoMBM1validation0 0"
    
    colour1="#00A0ff"
    colour2="navy"
    colour3="#ffA000"
    colour4="#800000"
    set output 'ConfUoMBM1validation0_0.eps'
    set style fill solid 0.8 border -1
    bin_width = 0.926911
    set boxwidth bin_width
    bin_number(x) = floor(x/bin_width)
    rounded(x) = bin_width * ( bin_number(x) + 0.5 )
    invsqrt2pi = 0.398942280401433
    normal(x,mu,sigma)=sigma<=0?1/0:invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2)
    stats 'ConfUoMBM1validation0_0.txt' using (rounded($1)) nooutput
    set xrange [STATS_min-bin_width/2.:STATS_max+bin_width/2.]
    set yrange [0:]
    plot 'ConfUoMBM1validation0_0.txt' using (rounded($1)):(1/(bin_width*STATS_records)) smooth frequency with boxes lc rgb colour1 notitle, normal(x,-0.14166974006432781,4.6345562297659741) with lines lc rgb colour2 lw 5 notitle
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-21
      • 2012-11-09
      • 2013-06-20
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多