@@ -162,12 +162,37 @@ def on_update_layers(self) -> None:
162
162
163
163
def draw (self ) -> None :
164
164
"""Clear the axes and histogram the currently selected layer/slice."""
165
+
166
+ # get the colormap from the layer depending on its type
167
+ if isinstance (self .layers [0 ], napari .layers .Points ):
168
+ colormap = self .layers [0 ].face_colormap
169
+ self .viewer .layers [0 ].face_color = self .x_axis_key
170
+ elif isinstance (self .layers [0 ], napari .layers .Vectors ):
171
+ colormap = self .layers [0 ].edge_colormap
172
+ self .viewer .layers [0 ].edge_color = self .x_axis_key
173
+ elif isinstance (self .layers [0 ], napari .layers .Labels ):
174
+ colormap = self .layers [0 ].colormap
175
+ self .viewer .layers [0 ].color = self .x_axis_key
176
+ else :
177
+ colormap = None
178
+ self .viewer .layers [self .layers [0 ].name ].refresh_colors (True )
179
+
180
+ # Draw the histogram
165
181
data , x_axis_name = self ._get_data ()
166
182
167
183
if data is None :
168
184
return
169
185
170
- self .axes .hist (data , bins = 50 , edgecolor = "white" , linewidth = 0.3 )
186
+ _ , bins , patches = self .axes .hist (data , bins = 50 , edgecolor = "white" , linewidth = 0.3 )
187
+
188
+ # recolor the histogram plot
189
+ if colormap is not None :
190
+ self .bins_norm = (bins - bins .min ())/ (bins .max () - bins .min ())
191
+ colors = colormap .map (self .bins_norm )
192
+
193
+ # Set histogram style:
194
+ for idx , patch in enumerate (patches ):
195
+ patch .set_facecolor (colors [idx ])
171
196
172
197
# set ax labels
173
198
self .axes .set_xlabel (x_axis_name )
0 commit comments