44import numpy as np
55import numpy .typing as npt
66from matplotlib .container import BarContainer
7+ from napari .layers import Image
8+ from napari .layers ._multiscale_data import MultiScaleData
79from qtpy .QtWidgets import (
810 QComboBox ,
911 QLabel ,
@@ -26,8 +28,9 @@ def _get_bins(data: npt.NDArray[Any]) -> npt.NDArray[Any]:
2628 step = np .ceil (np .ptp (data ) / 100 )
2729 return np .arange (np .min (data ), np .max (data ) + step , step )
2830 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 )
3134
3235
3336class HistogramWidget (SingleAxesWidget ):
@@ -67,14 +70,18 @@ def draw(self) -> None:
6770 """
6871 Clear the axes and histogram the currently selected layer/slice.
6972 """
70- layer = self .layers [0 ]
73+ layer : Image = self .layers [0 ]
74+ data = layer .data
7175
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 :
7380 # 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 ]
7583 self .axes .set_title (f"z={ self .current_z } " )
76- else :
77- data = layer .data
84+
7885 # Read data into memory if it's a dask array
7986 data = np .asarray (data )
8087
0 commit comments