|
20 | 20 | _COLORS= {"r":"tab:red","g":"tab:green","b":"tab:blue"}
|
21 | 21 |
|
22 | 22 |
|
| 23 | +def_get_bins(data:npt.NDArray[Any])->npt.NDArray[Any]: |
| 24 | +ifdata.dtype.kindin {"i","u"}: |
| 25 | +# Make sure integer data types have integer sized bins |
| 26 | +step=np.ceil(np.ptp(data)/100) |
| 27 | +returnnp.arange(np.min(data),np.max(data)+step,step) |
| 28 | +else: |
| 29 | +# For other data types, just have 128 evenly spaced bins |
| 30 | +returnnp.linspace(np.min(data),np.max(data),100) |
| 31 | + |
| 32 | + |
23 | 33 | classHistogramWidget(SingleAxesWidget):
|
24 | 34 | """
|
25 | 35 | Display a histogram of the currently selected layer.
|
@@ -70,13 +80,7 @@ def draw(self) -> None:
|
70 | 80 |
|
71 | 81 | # Important to calculate bins after slicing 3D data, to avoid reading
|
72 | 82 | # whole cube into memory.
|
73 |
| -ifdata.dtype.kindin {"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) |
| 83 | +bins=_get_bins(data) |
80 | 84 |
|
81 | 85 | iflayer.rgb:
|
82 | 86 | # Histogram RGB channels independently
|
@@ -215,9 +219,9 @@ def draw(self) -> None:
|
215 | 219 | ifdataisNone:
|
216 | 220 | return
|
217 | 221 |
|
218 |
| -_,bins,patches=self.axes.hist( |
219 |
| -data,bins=50,edgecolor="white",linewidth=0.3 |
220 |
| - ) |
| 222 | +bins=_get_bins(data) |
| 223 | + |
| 224 | +_,bins,patches=self.axes.hist(data,bins=bins.tolist()) |
221 | 225 | patches=cast(BarContainer,patches)
|
222 | 226 |
|
223 | 227 | # recolor the histogram plot
|
|