I needed to produce a histogram in gnuplot of multiple sets of raw data (i.e. not sumarised). The data in each dataset required binning and displaying on the same plot. This can be achieved by first defining a binning function which identifies which bin a given data point should be placed in:
The plot style is set up as preferred, in this case using solid filled boxes for the histogram with no border.
set style fill solid border -1 set boxwidth 0.5*binwidth
Finally, we plot the data using the smooth freq option which oversees the binning of the histogram data.
binwidth=10 plot 'data1.dat' using (bin($3,binwidth)):(1.0) smooth freq with boxes, 'data2.dat' using (0.5*binwidth+bin($3,binwidth)):(1.0) smooth freq with boxes
Here we have defined a variable binwidth to store the width of each bin in the histogram. The y-value (1.0) indicates that each value in the bin should increment the bar height by 1.