File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,19 @@ def bins_num(self, num: int) -> None:
135135
136136 def autoset_widget_bins (self , data : npt .NDArray [Any ]) -> None :
137137 """Update widgets with bins determined from the image data"""
138- bins = np .linspace (np .min (data ), np .max (data ), 100 , dtype = data .dtype )
138+ if data .dtype .kind in {"i" , "u" }:
139+ # Make sure integer data types have integer sized bins
140+ # We can't use unsigned ints when calculating the step, otherwise
141+ # the following warning is raised:
142+ # 'RuntimeWarning: overflow encountered in scalar subtract'
143+ step = (
144+ abs (np .min (data ).astype (int ) - np .max (data ).astype (int )) // 100
145+ )
146+ step = max (1 , step )
147+ bins = np .arange (np .min (data ), np .max (data ) + step , step )
148+ else :
149+ bins = np .linspace (np .min (data ), np .max (data ), 100 )
150+
139151 self .bins_start = bins [0 ]
140152 self .bins_stop = bins [- 1 ]
141153 self .bins_num = bins .size
You can’t perform that action at this time.
0 commit comments