Two dimensional histograms are defined by the following struct,
size_t nx, ny
- This is the number of histogram bins in the x and y directions.
double * xrange
- The ranges of the bins in the x-direction are stored in an array of nx + 1 elements pointed to by xrange.
double * yrange
- The ranges of the bins in the y-direction are stored in an array of ny + 1 elements pointed to by yrange.
double * bin
- The counts for each bin are stored in an array pointed to by bin. The bins are floating-point numbers, so you can increment them by non-integer values if necessary. The array bin stores the two dimensional array of bins in a single block of memory according to the mapping
bin(i,j)
=bin[i * ny + j]
.
The range for bin(i,j)
is given by xrange[i]
to
xrange[i+1]
in the x-direction and yrange[j]
to
yrange[j+1]
in the y-direction. Each bin is inclusive at the lower
end and exclusive at the upper end. Mathematically this means that the
bins are defined by the following inequality,
bin(i,j) corresponds to xrange[i] <= x < xrange[i+1] and yrange[j] <= y < yrange[j+1]
Note that any samples which fall on the upper sides of the histogram are excluded. If you want to include these values for the side bins you will need to add an extra row or column to your histogram.
The gsl_histogram2d
struct and its associated functions are
defined in the header file gsl_histogram2d.h.