Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c59f1e2

Browse files
p-j-smithdstansby
authored andcommitted
ensure histograms of integer data have equal bin width
1 parent 2fea1b0 commit c59f1e2

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
@@ -70,7 +70,12 @@ def draw(self) -> None:
7070

7171
# Important to calculate bins after slicing 3D data, to avoid reading
7272
# whole cube into memory.
73-
bins = np.linspace(np.min(data), np.max(data), 100, dtype=data.dtype)
73+
if data.dtype.kind == "i":
74+
# Make sure integer data types have integer sized bins
75+
step = (np.max(data) - np.min(data)) // 100
76+
bins = np.arange(np.min(data), np.max(data) + step, step)
77+
else:
78+
bins = np.linspace(np.min(data), np.max(data), 100)
7479

7580
if layer.rgb:
7681
# Histogram RGB channels independently

0 commit comments

Comments
 (0)