|
4 | 4 | import numpy as np |
5 | 5 | import numpy.typing as npt |
6 | 6 | from matplotlib.container import BarContainer |
7 | | -from qtpy.QtWidgets import QComboBox, QLabel, QVBoxLayout, QWidget |
| 7 | +from qtpy.QtWidgets import ( |
| 8 | + QComboBox, |
| 9 | + QLabel, |
| 10 | + QVBoxLayout, |
| 11 | + QWidget, |
| 12 | +) |
8 | 13 |
|
9 | 14 | from .base import SingleAxesWidget |
10 | 15 | from .features import FEATURES_LAYER_TYPES |
@@ -65,20 +70,26 @@ def draw(self) -> None: |
65 | 70 |
|
66 | 71 | # Important to calculate bins after slicing 3D data, to avoid reading |
67 | 72 | # whole cube into memory. |
68 | | - bins = np.linspace(np.min(data), np.max(data), 100) |
| 73 | + if data.dtype.kind in {"i", "u"}: |
| 74 | + # Make sure integer data types have integer sized bins |
| 75 | + step = abs(np.max(data) - np.min(data)) // 100 |
| 76 | + step = max(1, step) |
| 77 | + bins = np.arange(np.min(data), np.max(data) + step, step) |
| 78 | + else: |
| 79 | + bins = np.linspace(np.min(data), np.max(data), 100) |
69 | 80 |
|
70 | 81 | if layer.rgb: |
71 | 82 | # Histogram RGB channels independently |
72 | 83 | for i, c in enumerate("rgb"): |
73 | 84 | self.axes.hist( |
74 | 85 | data[..., i].ravel(), |
75 | | - bins=bins, |
| 86 | + bins=bins.tolist(), |
76 | 87 | label=c, |
77 | 88 | histtype="step", |
78 | 89 | color=_COLORS[c], |
79 | 90 | ) |
80 | 91 | else: |
81 | | - self.axes.hist(data.ravel(), bins=bins, label=layer.name) |
| 92 | + self.axes.hist(data.ravel(), bins=bins.tolist(), label=layer.name) |
82 | 93 |
|
83 | 94 | self._contrast_lines = [ |
84 | 95 | self.axes.axvline(lim, color="white") |
|
0 commit comments