@@ -25,9 +25,10 @@ def __init__(
2525 ----------
2626 data
2727 image_graphic
28- nbins
29- flank_divisor: float, default 5.0
30- set `np.inf` for no flanks
28+ nbins: int, defaut 100.
29+ Total number of bins used in the histogram
30+ flank_divisor: float, default 5.0.
31+ Fraction of empty histogram bins on the tails of the distribution set `np.inf` for no flanks
3132 kwargs
3233 """
3334 super ().__init__ (** kwargs )
@@ -161,9 +162,10 @@ def _calculate_histogram(self, data):
161162 hist , edges = np .histogram (data_ss , bins = self ._nbins )
162163
163164 # used if data ptp <= 10 because event things get weird
164- # with tiny world objects due to floating point error
165+ # with tiny world objects due to floating point error
165166 # so if ptp <= 10, scale up by a factor
166- self ._scale_factor : int = max (1 , 100 * int (10 / np .ptp (data_ss )))
167+ data_interval = edges [- 1 ] - edges [0 ]
168+ self ._scale_factor : int = max (1 , 100 * int (10 / data_interval ))
167169
168170 edges = edges * self ._scale_factor
169171
@@ -178,15 +180,17 @@ def _calculate_histogram(self, data):
178180 )
179181
180182 edges_flanked = np .concatenate ((flank_left , edges , flank_right ))
181- np .unique (np .diff (edges_flanked ))
182183
183184 hist_flanked = np .concatenate (
184185 (np .zeros (flank_nbins ), hist , np .zeros (flank_nbins ))
185186 )
186187
187188 # scale 0-100 to make it easier to see
188189 # float32 data can produce unnecessarily high values
189- hist_scaled = hist_flanked / (hist_flanked .max () / 100 )
190+ hist_scale_value = hist_flanked .max ()
191+ if np .allclose (hist_scale_value , 0 ):
192+ hist_scale_value = 1
193+ hist_scaled = hist_flanked / (hist_scale_value / 100 )
190194
191195 if edges_flanked .size > hist_scaled .size :
192196 # we don't care about accuracy here so if it's off by 1-2 bins that's fine
0 commit comments