4
4
import numpy as np
5
5
import numpy .typing as npt
6
6
from matplotlib .container import BarContainer
7
+ from napari .layers import Image
8
+ from napari .layers ._multiscale_data import MultiScaleData
7
9
from qtpy .QtWidgets import (
8
10
QComboBox ,
9
11
QLabel ,
@@ -26,8 +28,9 @@ def _get_bins(data: npt.NDArray[Any]) -> npt.NDArray[Any]:
26
28
step = np .ceil (np .ptp (data ) / 100 )
27
29
return np .arange (np .min (data ), np .max (data ) + step , step )
28
30
else :
29
- # For other data types, just have 128 evenly spaced bins
30
- return np .linspace (np .min (data ), np .max (data ), 100 )
31
+ # For other data types, just have 100 evenly spaced bins
32
+ # (and 101 bin edges)
33
+ return np .linspace (np .min (data ), np .max (data ), 101 )
31
34
32
35
33
36
class HistogramWidget (SingleAxesWidget ):
@@ -67,14 +70,18 @@ def draw(self) -> None:
67
70
"""
68
71
Clear the axes and histogram the currently selected layer/slice.
69
72
"""
70
- layer = self .layers [0 ]
73
+ layer : Image = self .layers [0 ]
74
+ data = layer .data
71
75
72
- if layer .data .ndim - layer .rgb == 3 :
76
+ if isinstance (layer .data , MultiScaleData ):
77
+ data = data [layer .data_level ]
78
+
79
+ if layer .ndim - layer .rgb == 3 :
73
80
# 3D data, can be single channel or RGB
74
- data = layer .data [self .current_z ]
81
+ # Slice in z dimension
82
+ data = data [self .current_z ]
75
83
self .axes .set_title (f"z={ self .current_z } " )
76
- else :
77
- data = layer .data
84
+
78
85
# Read data into memory if it's a dask array
79
86
data = np .asarray (data )
80
87
0 commit comments