Skip to content

Commit 322eda8

Browse files
committed
ensure histograms of integer data have equal bin width
1 parent 1b04375 commit 322eda8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/napari_matplotlib/histogram.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ def draw(self) -> None:
5353

5454
# Important to calculate bins after slicing 3D data, to avoid reading
5555
# whole cube into memory.
56-
bins = np.linspace(np.min(data), np.max(data), 100, dtype=data.dtype)
56+
if data.dtype.kind == "i":
57+
# Make sure integer data types have integer sized bins
58+
step = (np.max(data) - np.min(data)) // 100
59+
bins = np.arange(np.min(data), np.max(data) + step, step)
60+
else:
61+
bins = np.linspace(np.min(data), np.max(data), 100)
5762

5863
if layer.rgb:
5964
# Histogram RGB channels independently

0 commit comments

Comments
 (0)