Skip to content

Use integer bins for integer data in HistogramWidget #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 15, 2024
Prev Previous commit
Next Next commit
ensure histograms of integer data have equal bin width
  • Loading branch information
p-j-smith authored and dstansby committed Jan 13, 2024
commit c59f1e2c42fd0e3d9b73c26d749c6ecc4d4fa3dc
7 changes: 6 additions & 1 deletion src/napari_matplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def draw(self) -> None:

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

if layer.rgb:
# Histogram RGB channels independently
Expand Down