@@ -25,8 +25,8 @@ def __init__(
25
25
----------
26
26
data
27
27
image_graphic
28
- nbins
29
- flank_divisor: float, default 5.0
28
+ nbins: int, defaut 100. Total number of bins used in the histogram
29
+ flank_divisor: float, default 5.0. Fraction of empty histogram bins on the tails of the distribution
30
30
set `np.inf` for no flanks
31
31
kwargs
32
32
"""
@@ -161,9 +161,10 @@ def _calculate_histogram(self, data):
161
161
hist , edges = np .histogram (data_ss , bins = self ._nbins )
162
162
163
163
# used if data ptp <= 10 because event things get weird
164
- # with tiny world objects due to floating point error
164
+ # with tiny world objects due to floating point error
165
165
# so if ptp <= 10, scale up by a factor
166
- self ._scale_factor : int = max (1 , 100 * int (10 / np .ptp (data_ss )))
166
+ data_interval = edges [- 1 ] - edges [0 ]
167
+ self ._scale_factor : int = max (1 , 100 * int (10 / data_interval ))
167
168
168
169
edges = edges * self ._scale_factor
169
170
@@ -178,15 +179,17 @@ def _calculate_histogram(self, data):
178
179
)
179
180
180
181
edges_flanked = np .concatenate ((flank_left , edges , flank_right ))
181
- np .unique (np .diff (edges_flanked ))
182
182
183
183
hist_flanked = np .concatenate (
184
184
(np .zeros (flank_nbins ), hist , np .zeros (flank_nbins ))
185
185
)
186
186
187
187
# scale 0-100 to make it easier to see
188
188
# float32 data can produce unnecessarily high values
189
- hist_scaled = hist_flanked / (hist_flanked .max () / 100 )
189
+ hist_scale_value = hist_flanked .max ()
190
+ if np .allclose (hist_scale_value , 0 ):
191
+ hist_scale_value = 1
192
+ hist_scaled = hist_flanked / (hist_scale_value / 100 )
190
193
191
194
if edges_flanked .size > hist_scaled .size :
192
195
# we don't care about accuracy here so if it's off by 1-2 bins that's fine
0 commit comments