Search code examples
gnuplothistogram

How to export from gnuplot to extern datafile the frequency counts used to generate a histogram?


To plot a histogram I follow the book Gnuplot in Action and I use

binc(bin_width,x) = bin_width * ( int(x/bin_width) + 0.5 )

and to plot I use

plot 'datafile' u (binc(bin_width,$1)) : (1.0/size_sample ) smooth frequency

I have understood that smooth frecuency create a frecuency count for each bin and this is used by plot to make the histogram

But, How can I create a variable that contain the frecuency, I want do this to export the values of each bin's frecuency counts to a file, for example.


Solution

  • You can redirect the plot and save it in text format by setting table variable.

    binc(bin_width,x) = bin_width * ( int(x/bin_width) + 0.5 )
    set table "hist.dat"
    plot 'datafile' u (binc(bin_width,$1)) : (1.0/size_sample ) smooth frequency
    unset table
    

    Your histogram will be saved in the file name "hist.dat".