@@ -108,7 +108,7 @@ def plot_matplotlib(self, data_plot, **backend_kwargs):
108108 fig = self .figure
109109 nrows = 2
110110 ncols = 2
111- if sorting_analyzer .has_extension ("correlograms" ) or sorting_analyzer .has_extension ("spike_amplitudes " ):
111+ if sorting_analyzer .has_extension ("correlograms" ) and sorting_analyzer .has_extension ("template_similarity " ):
112112 ncols += 1
113113 if sorting_analyzer .has_extension ("waveforms" ):
114114 ncols += 1
@@ -117,31 +117,30 @@ def plot_matplotlib(self, data_plot, **backend_kwargs):
117117 gs = fig .add_gridspec (nrows , ncols )
118118 col_counter = 0
119119
120- if sorting_analyzer .has_extension ("unit_locations" ):
121- ax1 = fig .add_subplot (gs [:2 , col_counter ])
122- # UnitLocationsPlotter().do_plot(dp.plot_data_unit_locations, ax=ax1)
123- w = UnitLocationsWidget (
124- sorting_analyzer ,
125- unit_ids = [unit_id ],
126- unit_colors = unit_colors ,
127- plot_legend = False ,
128- backend = "matplotlib" ,
129- ax = ax1 ,
130- ** unitlocationswidget_kwargs ,
131- )
132- col_counter = col_counter + 1
133-
134- unit_locations = sorting_analyzer .get_extension ("unit_locations" ).get_data (outputs = "by_unit" )
135- unit_location = unit_locations [unit_id ]
136- x , y = unit_location [0 ], unit_location [1 ]
137- ax1 .set_xlim (x - 80 , x + 80 )
138- ax1 .set_ylim (y - 250 , y + 250 )
139- ax1 .set_xticks ([])
140- ax1 .set_xlabel (None )
141- ax1 .set_ylabel (None )
142-
143- ax2 = fig .add_subplot (gs [:2 , col_counter ])
144- w = UnitWaveformsWidget (
120+ # Unit locations and unit waveform plots are always generated
121+ ax_unit_locations = fig .add_subplot (gs [:2 , col_counter ])
122+ _ = UnitLocationsWidget (
123+ sorting_analyzer ,
124+ unit_ids = [unit_id ],
125+ unit_colors = unit_colors ,
126+ plot_legend = False ,
127+ backend = "matplotlib" ,
128+ ax = ax_unit_locations ,
129+ ** unitlocationswidget_kwargs ,
130+ )
131+ col_counter += 1
132+
133+ unit_locations = sorting_analyzer .get_extension ("unit_locations" ).get_data (outputs = "by_unit" )
134+ unit_location = unit_locations [unit_id ]
135+ x , y = unit_location [0 ], unit_location [1 ]
136+ ax_unit_locations .set_xlim (x - 80 , x + 80 )
137+ ax_unit_locations .set_ylim (y - 250 , y + 250 )
138+ ax_unit_locations .set_xticks ([])
139+ ax_unit_locations .set_xlabel (None )
140+ ax_unit_locations .set_ylabel (None )
141+
142+ ax_unit_waveforms = fig .add_subplot (gs [:2 , col_counter ])
143+ _ = UnitWaveformsWidget (
145144 sorting_analyzer ,
146145 unit_ids = [unit_id ],
147146 unit_colors = unit_colors ,
@@ -151,46 +150,47 @@ def plot_matplotlib(self, data_plot, **backend_kwargs):
151150 plot_legend = False ,
152151 sparsity = sparsity ,
153152 backend = "matplotlib" ,
154- ax = ax2 ,
153+ ax = ax_unit_waveforms ,
155154 ** unitwaveformswidget_kwargs ,
156155 )
157- col_counter = col_counter + 1
156+ col_counter += 1
158157
159- ax2 .set_title (None )
158+ ax_unit_waveforms .set_title (None )
160159
161160 if sorting_analyzer .has_extension ("waveforms" ):
162- ax3 = fig .add_subplot (gs [:2 , col_counter ])
161+ ax_waveform_density = fig .add_subplot (gs [:2 , col_counter ])
163162 UnitWaveformDensityMapWidget (
164163 sorting_analyzer ,
165164 unit_ids = [unit_id ],
166165 unit_colors = unit_colors ,
167166 use_max_channel = True ,
168167 same_axis = False ,
169168 backend = "matplotlib" ,
170- ax = ax3 ,
169+ ax = ax_waveform_density ,
171170 ** unitwaveformdensitymapwidget_kwargs ,
172171 )
173- ax3 . set_ylabel ( None )
174- col_counter = col_counter + 1
172+ col_counter += 1
173+ ax_waveform_density . set_ylabel ( None )
175174
176- if sorting_analyzer .has_extension ("correlograms" ):
177- ax4 = fig .add_subplot (gs [:2 , col_counter ])
175+ if sorting_analyzer .has_extension ("correlograms" ) and sorting_analyzer . has_extension ( "template_similarity" ) :
176+ ax_correlograms = fig .add_subplot (gs [:2 , col_counter ])
178177 AutoCorrelogramsWidget (
179178 sorting_analyzer ,
180179 unit_ids = [unit_id ],
181180 unit_colors = unit_colors ,
182181 backend = "matplotlib" ,
183- ax = ax4 ,
182+ ax = ax_correlograms ,
184183 ** autocorrelogramswidget_kwargs ,
185184 )
185+ col_counter += 1
186186
187- ax4 .set_title (None )
188- ax4 .set_yticks ([])
187+ ax_correlograms .set_title (None )
188+ ax_correlograms .set_yticks ([])
189189
190190 if sorting_analyzer .has_extension ("spike_amplitudes" ):
191- ax5 = fig .add_subplot (gs [2 , :col_counter ])
192- ax6 = fig .add_subplot (gs [2 , col_counter ])
193- axes = np .array ([ax5 , ax6 ])
191+ ax_spike_amps = fig .add_subplot (gs [2 , : col_counter - 1 ])
192+ ax_amps_distribution = fig .add_subplot (gs [2 , col_counter - 1 ])
193+ axes = np .array ([ax_spike_amps , ax_amps_distribution ])
194194 AmplitudesWidget (
195195 sorting_analyzer ,
196196 unit_ids = [unit_id ],
0 commit comments