Histogram bin estimator that uses the minimum width of a relaxed Freedman-Diaconis and Sturges estimators if the FD bin width does not result in a large number of bins. The relaxed Freedman-Diaconis estimator limits the bin width to half the sqrt estimated to avoid small bins.
(x, range)
| 228 | |
| 229 | |
| 230 | def _hist_bin_auto(x, range): |
| 231 | """ |
| 232 | Histogram bin estimator that uses the minimum width of a relaxed |
| 233 | Freedman-Diaconis and Sturges estimators if the FD bin width does |
| 234 | not result in a large number of bins. The relaxed Freedman-Diaconis estimator |
| 235 | limits the bin width to half the sqrt estimated to avoid small bins. |
| 236 | |
| 237 | The FD estimator is usually the most robust method, but its width |
| 238 | estimate tends to be too large for small `x` and bad for data with limited |
| 239 | variance. The Sturges estimator is quite good for small (<1000) datasets |
| 240 | and is the default in the R language. This method gives good off-the-shelf |
| 241 | behaviour. |
| 242 | |
| 243 | |
| 244 | Parameters |
| 245 | ---------- |
| 246 | x : array_like |
| 247 | Input data that is to be histogrammed, trimmed to range. May not |
| 248 | be empty. |
| 249 | range : Tuple with range for the histogram |
| 250 | |
| 251 | Returns |
| 252 | ------- |
| 253 | h : An estimate of the optimal bin width for the given data. |
| 254 | |
| 255 | See Also |
| 256 | -------- |
| 257 | _hist_bin_fd, _hist_bin_sturges |
| 258 | """ |
| 259 | fd_bw = _hist_bin_fd(x, range) |
| 260 | sturges_bw = _hist_bin_sturges(x, range) |
| 261 | sqrt_bw = _hist_bin_sqrt(x, range) |
| 262 | # heuristic to limit the maximal number of bins |
| 263 | fd_bw_corrected = max(fd_bw, sqrt_bw / 2) |
| 264 | return min(fd_bw_corrected, sturges_bw) |
| 265 | |
| 266 | |
| 267 | # Private dict initialized at module load time |
nothing calls this directly
no test coverage detected
searching dependent graphs…