1111
1212
1313class ScatterBaseWidget (NapariMPLWidget ):
14+ # opacity value for the markers
15+ _marker_alpha = 0.5
16+
17+ # flag set to True if histogram should be used
18+ # for plotting large points
19+ _histogram_for_large_data = True
20+
21+ # if the number of points is greater than this value,
22+ # the scatter is plotted as a 2dhist
23+ _threshold_to_switch_to_histogram = 500
24+
1425 def __init__ (
1526 self ,
1627 napari_viewer : napari .viewer .Viewer ,
17- marker_alpha : float = 0.5 ,
18- histogram_for_large_data : bool = True ,
1928 ):
2029 super ().__init__ (napari_viewer )
2130
22- # flag set to True if histogram should be used
23- # for plotting large points
24- self .histogram_for_large_data = histogram_for_large_data
25-
26- # set plotting visualization attributes
27- self ._marker_alpha = 0.5
28-
2931 self .axes = self .canvas .figure .subplots ()
3032 self .update_layers (None )
3133
32- @property
33- def marker_alpha (self ) -> float :
34- """Alpha (opacity) for the scatter markers"""
35- return self ._marker_alpha
36-
37- @marker_alpha .setter
38- def marker_alpha (self , alpha : float ):
39- self ._marker_alpha = alpha
40- self ._draw ()
41-
4234 def clear (self ) -> None :
4335 self .axes .clear ()
4436
@@ -52,15 +44,15 @@ def draw(self) -> None:
5244 # don't plot if there isn't data
5345 return
5446
55- if self .histogram_for_large_data and (data [0 ].size > 500 ):
47+ if self ._histogram_for_large_data and (data [0 ].size > 500 ):
5648 self .axes .hist2d (
5749 data [0 ].ravel (),
5850 data [1 ].ravel (),
5951 bins = 100 ,
6052 norm = mcolor .LogNorm (),
6153 )
6254 else :
63- self .axes .scatter (data [0 ], data [1 ], alpha = self .marker_alpha )
55+ self .axes .scatter (data [0 ], data [1 ], alpha = self ._marker_alpha )
6456
6557 self .axes .set_xlabel (x_axis_name )
6658 self .axes .set_ylabel (y_axis_name )
@@ -95,13 +87,9 @@ class ScatterWidget(ScatterBaseWidget):
9587 def __init__ (
9688 self ,
9789 napari_viewer : napari .viewer .Viewer ,
98- marker_alpha : float = 0.5 ,
99- histogram_for_large_data : bool = True ,
10090 ):
10191 super ().__init__ (
10292 napari_viewer ,
103- marker_alpha = marker_alpha ,
104- histogram_for_large_data = histogram_for_large_data ,
10593 )
10694
10795 def _get_data (self ) -> Tuple [List [np .ndarray ], str , str ]:
@@ -129,15 +117,11 @@ class FeaturesScatterWidget(ScatterBaseWidget):
129117 def __init__ (
130118 self ,
131119 napari_viewer : napari .viewer .Viewer ,
132- marker_alpha : float = 0.5 ,
133- histogram_for_large_data : bool = True ,
134120 key_selection_gui : bool = True ,
135121 ):
136122 self ._key_selection_widget = None
137123 super ().__init__ (
138124 napari_viewer ,
139- marker_alpha = marker_alpha ,
140- histogram_for_large_data = histogram_for_large_data ,
141125 )
142126
143127 if key_selection_gui is True :
0 commit comments