Skip to content

Commit 65e84f8

Browse files
committed
Make HistogramWidget bins_num widget correspond to number of bins rather than number of bin edges
1 parent 08a5086 commit 65e84f8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/napari_matplotlib/histogram.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def autoset_widget_bins(self, data: npt.NDArray[Any]) -> None:
148148

149149
self.bins_start = bins[0]
150150
self.bins_stop = bins[-1]
151-
self.bins_num = bins.size
151+
self.bins_num = bins.size - 1
152152

153153
for widget in self._bin_widgets.values():
154154
widget.blockSignals(False)
@@ -208,11 +208,13 @@ def draw(self) -> None:
208208
# whole cube into memory.
209209
if data.dtype.kind in {"i", "u"}:
210210
# Make sure integer data types have integer sized bins
211-
step = abs(self.bins_stop - self.bins_start) // (self.bins_num - 1)
211+
step = abs(self.bins_stop - self.bins_start) // (self.bins_num)
212212
step = max(1, step)
213213
bins = np.arange(self.bins_start, self.bins_stop + step, step)
214214
else:
215-
bins = np.linspace(self.bins_start, self.bins_stop, self.bins_num)
215+
bins = np.linspace(
216+
self.bins_start, self.bins_stop, self.bins_num + 1
217+
)
216218

217219
if layer.rgb:
218220
# Histogram RGB channels independently

0 commit comments

Comments
 (0)