Skip to content

Commit d56942b

Browse files
committed
Fix calculation of bins from widget values
1 parent 88760cf commit d56942b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/napari_matplotlib/histogram.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ def autoset_widget_bins(self, data: npt.NDArray[Any]) -> None:
136136
"""Update widgets with bins determined from the image data"""
137137
if data.dtype.kind in {"i", "u"}:
138138
# Make sure integer data types have integer sized bins
139-
# We can't use unsigned ints when calculating the step, otherwise
140-
# the following warning is raised:
141-
# 'RuntimeWarning: overflow encountered in scalar subtract'
142-
step = abs(
143-
np.min(data).astype(int) - np.max(data).astype(int) // 100
144-
)
139+
step = abs(np.max(data) - np.min(data)) // 100
145140
step = max(1, step)
146141
bins = np.arange(np.min(data), np.max(data) + step, step)
147142
else:
@@ -213,7 +208,7 @@ def draw(self) -> None:
213208
# whole cube into memory.
214209
if data.dtype.kind in {"i", "u"}:
215210
# Make sure integer data types have integer sized bins
216-
step = abs((self.bins_start - self.bins_stop) // self.bins_num)
211+
step = abs(self.bins_stop - self.bins_start) // self.bins_num
217212
step = max(1, step)
218213
bins = np.arange(self.bins_start, self.bins_stop + step, step)
219214
else:

0 commit comments

Comments
 (0)