Changed percentile calculation to be less susceptible to outliers
@@ -100,7 +100,7 @@ class Histo:
return n_bins, bin_edges
- def _adaptive_binning(self, x, n_bins, weights=None, lower_cutoff_percentile=0.0, upper_cutoff_percentile=100.0):
+ def _adaptive_binning(self, x, n_bins, weights=None, lower_cutoff_percentile=1., upper_cutoff_percentile=99.0):
edges = weighted_quantile(
x,
quantiles=np.linspace(lower_cutoff_percentile / 100.0, upper_cutoff_percentile / 100.0, n_bins + 1),
@@ -109,7 +109,7 @@ class Histo:
)
# Increase range by some safety margin
- range_ = (np.nanmin(x) - 0.1 * (edges[1] - edges[0]), np.nanmax(x) + 0.1 * (edges[-1] - edges[-2]))
+ range_ = (np.nanmin(x) - 0.5 * (edges[1] - edges[0]), np.nanmax(x) + 0.5 * (edges[-1] - edges[-2]))
logger.debug("Increasing histogram range from %s to %s", (edges[0], edges[-1]), range_)
edges[0], edges[-1] = range_
