1515from .benchmark_base import Benchmark , BenchmarkStudy
1616from spikeinterface .core .basesorting import minimum_spike_dtype
1717from spikeinterface .core .sortinganalyzer import create_sorting_analyzer
18+ from .benchmark_plot_tools import fit_sigmoid , sigmoid
1819
1920
2021class PeakDetectionBenchmark (Benchmark ):
@@ -126,7 +127,7 @@ def create_benchmark(self, key):
126127 def plot_agreements_by_channels (self , case_keys = None , figsize = (15 , 15 )):
127128 if case_keys is None :
128129 case_keys = list (self .cases .keys ())
129- import pylab as plt
130+ import matplotlib . pyplot as plt
130131
131132 fig , axs = plt .subplots (ncols = len (case_keys ), nrows = 1 , figsize = figsize , squeeze = False )
132133
@@ -138,7 +139,7 @@ def plot_agreements_by_channels(self, case_keys=None, figsize=(15, 15)):
138139 def plot_agreements_by_units (self , case_keys = None , figsize = (15 , 15 )):
139140 if case_keys is None :
140141 case_keys = list (self .cases .keys ())
141- import pylab as plt
142+ import matplotlib . pyplot as plt
142143
143144 fig , axs = plt .subplots (ncols = len (case_keys ), nrows = 1 , figsize = figsize , squeeze = False )
144145
@@ -151,32 +152,39 @@ def plot_performances_vs_snr(self, case_keys=None, figsize=(15, 15), detect_thre
151152 if case_keys is None :
152153 case_keys = list (self .cases .keys ())
153154
155+ import matplotlib .pyplot as plt
156+
154157 fig , axs = plt .subplots (ncols = 1 , nrows = 3 , figsize = figsize )
155158
156159 for count , k in enumerate (("accuracy" , "recall" , "precision" )):
157160
158161 ax = axs [count ]
159162 for key in case_keys :
163+ color = self .get_colors ()[key ]
160164 label = self .cases [key ]["label" ]
161165
162166 analyzer = self .get_sorting_analyzer (key )
163167 metrics = analyzer .get_extension ("quality_metrics" ).get_data ()
164168 x = metrics ["snr" ].values
165169 y = self .get_result (key )["sliced_gt_comparison" ].get_performance ()[k ].values
166- ax .scatter (x , y , marker = "." , label = label )
170+ ax .scatter (x , y , marker = "." , label = label , color = color )
167171 ax .set_title (k )
168172 if detect_threshold is not None :
169173 ymin , ymax = ax .get_ylim ()
170174 ax .plot ([detect_threshold , detect_threshold ], [ymin , ymax ], "k--" )
171175
176+ popt = fit_sigmoid (x , y , p0 = None )
177+ xfit = np .linspace (0 , max (metrics ["snr" ].values ), 100 )
178+ ax .plot (xfit , sigmoid (xfit , * popt ), color = color )
179+
172180 if count == 2 :
173181 ax .legend ()
174182
175183 def plot_detected_amplitudes (self , case_keys = None , figsize = (15 , 5 ), detect_threshold = None ):
176184
177185 if case_keys is None :
178186 case_keys = list (self .cases .keys ())
179- import pylab as plt
187+ import matplotlib . pyplot as plt
180188
181189 fig , axs = plt .subplots (ncols = len (case_keys ), nrows = 1 , figsize = figsize , squeeze = False )
182190
@@ -201,7 +209,7 @@ def plot_deltas_per_cells(self, case_keys=None, figsize=(15, 5)):
201209
202210 if case_keys is None :
203211 case_keys = list (self .cases .keys ())
204- import pylab as plt
212+ import matplotlib . pyplot as plt
205213
206214 fig , axs = plt .subplots (ncols = len (case_keys ), nrows = 1 , figsize = figsize , squeeze = False )
207215 for count , key in enumerate (case_keys ):
@@ -222,12 +230,12 @@ def plot_template_similarities(self, case_keys=None, metric="l2", figsize=(15, 5
222230
223231 if case_keys is None :
224232 case_keys = list (self .cases .keys ())
225- import pylab as plt
233+ import matplotlib . pyplot as plt
226234
227235 fig , ax = plt .subplots (ncols = 1 , nrows = 1 , figsize = figsize , squeeze = True )
228236 for key in case_keys :
229237
230- import sklearn
238+ import sklearn . metrics
231239
232240 gt_templates = self .get_result (key )["gt_templates" ]
233241 found_templates = self .get_result (key )["templates" ]
@@ -244,14 +252,22 @@ def plot_template_similarities(self, case_keys=None, metric="l2", figsize=(15, 5
244252 else :
245253 distances [i ] = sklearn .metrics .pairwise_distances (a [None , :], b [None , :], metric )[0 , 0 ]
246254
255+ color = self .get_colors ()[key ]
256+
247257 label = self .cases [key ]["label" ]
248258 analyzer = self .get_sorting_analyzer (key )
249259 metrics = analyzer .get_extension ("quality_metrics" ).get_data ()
250260 x = metrics ["snr" ].values
251- ax .scatter (x , distances , marker = "." , label = label )
252- if detect_threshold is not None :
253- ymin , ymax = ax .get_ylim ()
254- ax .plot ([detect_threshold , detect_threshold ], [ymin , ymax ], "k--" )
261+ y = distances
262+ ax .scatter (x , y , marker = "." , label = label , color = color )
263+
264+ popt = fit_sigmoid (x , y , p0 = None )
265+ xfit = np .linspace (0 , max (metrics ["snr" ].values ), 100 )
266+ ax .plot (xfit , sigmoid (xfit , * popt ), color = color )
267+
268+ if detect_threshold is not None :
269+ ymin , ymax = ax .get_ylim ()
270+ ax .plot ([detect_threshold , detect_threshold ], [ymin , ymax ], "k--" )
255271
256272 ax .legend ()
257273 ax .set_xlabel ("snr" )
0 commit comments