I have seen in posts Normalizing histogram bins in Gnuplot that is possible to bin some x samples and plot a histogram, with
binwidth=5
bin(x,width)=width*floor(x/width) + binwidth/2.0
plot 'file.dat' using (bin($1, binwidth)):(1/(binwidth*num_points) smooth freq with boxes
I would like to achieve the same result of that post but with the 2D dataset ((x,y)-points) and plot a type of heat map of that data, for example with heat-map indicating the probability, or intensity (i.e. (number of samples)/(bin area)).
How could I compute the 2d-bin_plot with Gnuplot
?
Thank you very much for your help
Binning of 2D data is the same principle as for 1D. The special point about it is that the option
smooth freq
which is used for 1D binning will only accept one value for the bins (not two: x and y). Hence, you simply enumerate your bins from0
toBinCountX * BinCountY - 1
and define functionsBinValueX(), BinValueY()
to get back from your bin number to the x- and y-bin values.The test data section creates random x,y and z-values. The z-values within a x,y-bin will be added during the binning process.
Alternatively, depending on the data, a density plot could also be of interest.
Script: (works with gnuplot>=5.0.0)
Result: