Histogram 2D Contour Heat map Binning Issue

Hi, I have been using the Histogram 2D contour function to create a heatmap displaying a 3 dimensional dataset (X and Y for coordinates and Z for the heatmap color).

For the binning I have been using nbinsx and nbinsy to fine tune the heatmap. Unfortunately, I donโ€™t know how the binning is calculated using my inputted numbers. In the documentation it just says that my inputted numbers are โ€œused in an algorithm that will decide the optimal bin size such that the histogram best visualizes the distribution of the dataโ€.

If anyone could give me some insight as to how this binning algorithm works I would greatly appreciate it.

Thanks