 asymptotically optimal, which is
why it appears in most estimators. These are simply plug-in methods
that give good starting points for number of bins. In the equations
below, :math:`h` is the binwidth and :math:`n_h` is the number of
bins. All estimators that compute bin counts are recast to bin width
using the `ptp` of the data. The final bin count is obtained from
``np.round(np.ceil(range / h))``. The final bin width is often less
than what is returned by the estimators below.

'auto' (minimum bin width of the 'sturges' and 'fd' estimators)
    A compromise to get a good value. For small datasets the Sturges
    value will usually be chosen, while larger datasets will usually
    default to FD.  Avoids the overly conservative behaviour of FD
    and Sturges for small and large datasets respectively.
    Switchover point is usually :math:`a.size \approx 1000`.

'fd' (Freedman Diaconis Estimator)
    .. math:: h = 2 \frac{IQR}{n^{1/3}}

    The binwidth is proportional to the interquartile range (IQR)
    and inversely proportional to cube root of a.size. Can be too
    conservative for small datasets, but is quite good for large
    datasets. The IQR is very robust to outliers.

'scott'
    .. math:: h = \sigma \sqrt[3]{\frac{24 \sqrt{\pi}}{n}}

    The binwidth is proportional to the standard deviation of the
    data and inversely proportional to cube root of ``x.size``. Can
    be too conservative for small datasets, but is quite good for
    large datasets. The standard deviation is not very robust to
    outliers. Values are very similar to the Freedman-Diaconis
    estimator in the absence of outliers.

'rice'
    .. math:: n_h = 2n^{1/3}

    The number of bins is only proportional to cube root of
    ``a.size``. It tends to overestimate the number of bins and it
    does not take into account data variability.

'sturges'
    .. math:: n_h = \log _{2}(n) + 1

    The number of bins is the base 2 log of ``a.size``.  This
    estimator assumes normality of data and is too conservative for
    larger, non-normal datasets. This is the default method in R's
    ``hist`` method.

'doane'
    .. math:: n_h = 1 + \log_{2}(n) +
                    \log_{2}\left(1 + \frac{|g_1|}{\sigma_{g_1}}\right)

        g_1 = mean\left[\left(\frac{x - \mu}{\sigma}\right)^3\right]

        \sigma_{g_1} = \sqrt{\frac{6(n - 2)}{(n + 1)(n + 3)}}

    An improved version of Sturges' formula that produces better
    estimates for non-normal datasets. This estimator attempts to
    account for the skew of the data.

'sqrt'
    .. math:: n_h = \sqrt n

    The simplest and fastest estimator. Only takes into account the
    data size.

Additionally, if the data is of integer dtype, then the binwidth will never
be less than 1.

Examples
--------
>>> import numpy as np
>>> arr = np.array([0, 0, 0, 1, 2, 3, 3, 4, 5])
>>> np.histogram_bin_edges(arr, bins='auto', range=(0, 1))
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
>>> np.histogram_bin_edges(arr, bins=2)
array([0. , 2.5, 5. ])

For consistency with histogram, an array of pre-computed bins is
passed through unmodified:

>>> np.histogram_bin_edges(arr, [1, 2])
array([1, 2])

This function allows one set of bins to be computed, and reused across
multiple histograms:

>>> shared_bins = np.histogram_bin_edges(arr, bins='auto')
>>> shared_bins
array([0., 1., 2., 3., 4., 5.])

>>> group_id = np.array([0, 1, 1, 0, 1, 1, 0, 1, 1])
>>> hist_0, _ = np.histogram(arr[group_id == 0], bins=shared_bins)
>>> hist_1, _ = np.histogram(arr[group_id == 1], bins=shared_bins)

>>> hist_0; hist_1
array([1, 1, 0, 1, 0])
array([2, 0, 1, 1, 2])

Which gives more easily comparable results than using separate bins for
each histogram:

>>> hist_0, bins_0 = np.histogram(arr[group_id == 0], bins='auto')
>>> hist_1, bins_1 = np.histogram(arr[group_id == 1], bins='auto')
>>> hist_0; hist_1
array([1, 1, 1])
array([2, 1, 1, 2])
>>> bins_0; bins_1
array([0., 1., 2., 3.])
array([0.  , 1.25, 2.5 , 3.75, 5.  ])

)