0
votes

I have the following script to plot histograms:

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

This is supposed to be empirical realisation of some distribution, so to make it more clear I would like to:

  1. Normalize the bars appropriately so that they can be compared to a density function (I guess the sum of the areas of the bars should sum-up to unity? That would mean that the height of each bar should be divided by barWidth*numberOfElements)
  2. On the same picture plot the theoretical distribution function, given by a closed form formula (e.g. Gaussian)

How can I achieve this?

1

1 Answers

0
votes

I managed to solve this issue. (1) The normalization goes into the column after the colon, so the plot command becomes:

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

(2) Plotting of functions can't be easier, just do it after a coma as you would normally do

So the final outcome is:

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