1717
1818from matplotlib .ticker import FormatStrFormatter
1919
20- # def format_axis(ax):
21- # ax.spines['top'].set_visible(False)
22- # ax.spines['right'].set_visible(False)
23- # ax.get_xaxis().tick_bottom()
24- # ax.get_yaxis().tick_left()
25- # ax.xaxis.set_tick_params(size=6)
26- # ax.yaxis.set_tick_params(size=6)
27-
2820## eLife
2921def format_axis (ax ):
22+ ''' format axis to unified format
23+
24+ Arguments
25+ ---------
26+ ax : matplotlib axis object
27+ '''
3028 ax .spines ['top' ].set_visible (False )
3129 ax .spines ['right' ].set_visible (False )
3230 ax .get_xaxis ().tick_bottom ()
@@ -161,6 +159,13 @@ def get_combined_modevals(model, runinfo):
161159# %% COMPARISON VIOLIN PLOT
162160
163161def clip (vp , lr ):
162+ ''' clips off half of a violin plot for split violin plots
163+
164+ Arguments
165+ ---------
166+ vp : matplotlib violin plot object
167+ lr : str, one of ['l', 'r'] specifying whether we want to keep the left or right side of the violin plot
168+ '''
164169
165170 for b in vp ['bodies' ]:
166171 m = np .mean (b .get_paths ()[0 ].vertices [:, 0 ])
@@ -172,14 +177,17 @@ def clip(vp, lr):
172177
173178
174179def plot_compvp (trainedmodevals , controlmodevals , trainedmodel , regcomp = False , modnames = modnames , ifsets_to_quantile = [0 ,3 ]):
175- ''' Plot the comparison violin plot showing the distribution of tuning strengths
180+ ''' Plot the comparison violin plot showing the distribution of tuning strengths -- plotting format associated with original submission
176181
177182 Arguments
178183 ---------
179184 trainedmodevals : list [nr layers] of np.arrays, store performance of each neuron in trained model
180185 controlmodevals : list [nr layers] of np.arrays, store performance of each neuron in control model
181186 trainedmodel : dict
182-
187+ regcomp : bool, True if we are comparing ART and TDT, False if we are comparing trained and random models
188+ modnames : list of str, list of variables/feature sets that we are plotting e.g. "vel", "acc" etc.
189+ ifsets_to_quantile : list of ints, indices of variables in mod_names for which to add the 90% quantile
190+
183191 Returns
184192 -------
185193 fig : plt.figure, comparison violin plot
@@ -198,7 +206,6 @@ def plot_compvp(trainedmodevals, controlmodevals, trainedmodel, regcomp = False,
198206 controlcmap = matplotlib .cm .get_cmap ('Greys_r' ) #spatial_temporal
199207 else :
200208 controlcmap = matplotlib .cm .get_cmap (trainedmodel ['regression_cmap' ])
201- #cmaps = [trainedcmap, controlcmap]
202209
203210 ## SET OTHER PLOTTING VARIABLES
204211
@@ -218,7 +225,6 @@ def plot_compvp(trainedmodevals, controlmodevals, trainedmodel, regcomp = False,
218225 patches = []
219226
220227 ccolorindex = 3
221- #for (modevals, cmap, alpha, zorder, lr) in zip([controlmodevals, trainedmodevals], [controlcmap, trainedcmap], [[0.8, 0.5], [0.8, 0.7]], [2,1], ['r', 'l']):
222228 for (modevals , cmap , alpha , zorder , lr ) in zip ([controlmodevals , trainedmodevals ], [controlcmap , trainedcmap ], [[1 , 1 ], [1 , 1 ]], [2 ,1 ], ['r' , 'l' ]):
223229 for i , mod in enumerate (modevals ):
224230
@@ -264,7 +270,6 @@ def plot_compvp(trainedmodevals, controlmodevals, trainedmodel, regcomp = False,
264270 print ("empty array, can't do violin plot" , e )
265271 vp = None
266272
267- #patches.append(mpatches.Patch(color=cmap(cidx[i]), alpha=0.7))
268273 patches .append (mpatches .Patch (color = cmap (cidx [i ]), alpha = 1 ))
269274
270275 vps .append (vp )
@@ -299,14 +304,16 @@ def plot_compvp(trainedmodevals, controlmodevals, trainedmodel, regcomp = False,
299304
300305 return fig
301306
302- def plot_compvp_v3 (trainedmodevals , controlmodevals , trainedmodel , regcomp = False , modnames = modnames , ifsets_to_quantile = [ 0 , 3 ] ):
303- ''' Plot the comparison violin plot showing the distribution of tuning strengths
307+ def plot_compvp_v3 (trainedmodevals , controlmodevals , trainedmodel , regcomp = False , modnames = modnames ):
308+ ''' Plot the comparison violin plot showing the distribution of tuning strengths, plot format associated with eLife resubmission
304309
305310 Arguments
306311 ---------
307312 trainedmodevals : list [nr layers] of np.arrays, store performance of each neuron in trained model
308313 controlmodevals : list [nr layers] of np.arrays, store performance of each neuron in control model
309314 trainedmodel : dict
315+ regcomp : bool, True if we are comparing ART and TDT, False if we are comparing trained and random models
316+ modnames : list of str, list of variables/feature sets that we are plotting e.g. "vel", "acc" etc.
310317
311318 Returns
312319 -------
@@ -319,7 +326,6 @@ def plot_compvp_v3(trainedmodevals, controlmodevals, trainedmodel, regcomp = Fal
319326
320327 space = 0.8
321328 width = 0.6
322- #lspace = space*nmods + 1
323329 lspace = space * nmods + 1.6
324330
325331 trainedcmap = matplotlib .cm .get_cmap (trainedmodel ['cmap' ]) #spatial_temporal
@@ -328,7 +334,6 @@ def plot_compvp_v3(trainedmodevals, controlmodevals, trainedmodel, regcomp = Fal
328334 controlcmap = matplotlib .cm .get_cmap ('Greys_r' ) #spatial_temporal
329335 else :
330336 controlcmap = matplotlib .cm .get_cmap (trainedmodel ['regression_cmap' ])
331- #cmaps = [trainedcmap, controlcmap]
332337
333338 ## SET OTHER PLOTTING VARIABLES
334339
@@ -347,14 +352,10 @@ def plot_compvp_v3(trainedmodevals, controlmodevals, trainedmodel, regcomp = Fal
347352 patches = []
348353
349354 ccolorindex = 3
350- #for (modevals, cmap, alpha, zorder, lr) in zip([controlmodevals, trainedmodevals], [controlcmap, trainedcmap], [[0.8, 0.5], [0.8, 0.7]], [2,1], ['r', 'l']):
351355 for (modevals , cmap , alpha , zorder , lr ) in zip ([controlmodevals , trainedmodevals ], [controlcmap , trainedcmap ], [[1 , 1 ], [1 , 1 ]], [2 ,1 ], ['r' , 'l' ]):
352356 for i , mod in enumerate (modevals ):
353357
354- #print(mod)
355358 mod = [x .reshape ((- 1 ,)) for x in mod ]
356- #for x in mod:
357- # print(x.shape)
358359
359360 ##exclude r2 == 1 scores and r2 < -0.1
360361 mod = [x [(x != 1 ) & (x > - 0.1 )] for x in mod ]
@@ -393,47 +394,14 @@ def plot_compvp_v3(trainedmodevals, controlmodevals, trainedmodel, regcomp = Fal
393394 print ("empty array, can't do violin plot" , e )
394395 vp = None
395396 patches .append (mpatches .Patch (color = cmap (cidx [i ]), alpha = 1 ))
396- #patches.append(mpatches.Patch(color=cmap(cidx[i]), alpha=0.7))
397397 #patches.append(mpatches.Patch(color=matplotlib.cm.get_cmap('Greys_r') (cidx[i]), alpha=0.7)) ##eLife
398398
399399
400400 vps .append (vp )
401-
402- # #Quantiles
403- # q = 0.9
404- # marker = 's'
405-
406- # for i in ifsets_to_quantile:
407- # mod = modevals[i]
408-
409- # mod = [x[x != 1] for x in mod]
410-
411- # q90s = np.zeros((nlayers,))
412-
413- # for ilayer, layer in enumerate(mod):
414- # try:
415- # q90s[ilayer] = np.quantile(layer, q)
416- # except e:
417- # print(e)
418- # ax1.plot([ilayer*lspace+space*i+1 for ilayer in range(nlayers)],
419- # q90s, color=cmap(cidx[i]), marker=marker, alpha=alpha[0])
420-
421401
422402 format_axis (plt .gca ())
423403 format_axis (ax1 )
424404
425- ## SET AXIS WIDTHS
426- #for axis in ['top','bottom','left','right']:
427- # ax1.spines[axis].set_linewidth(1.5)
428-
429- # increase tick width
430- #ax1.tick_params(width=1.5, labels=18)
431-
432-
433- #ax1.yaxis.label.set_size(18)
434- #ax1.xaxis.label.set_size(18)
435-
436-
437405 leg = plt .legend (patches [5 :], modnames , loc = 'upper right' )
438406 ax1 .add_artist (leg )
439407 if not regcomp :
@@ -491,6 +459,7 @@ def plot_compvp_ee(trainedmodevals, controlmodevals, trainedmodel, regcomp = Fal
491459 trainedmodevals : list [nr layers] of np.arrays, store performance of each neuron in trained model
492460 controlmodevals : list [nr layers] of np.arrays, store performance of each neuron in control model
493461 trainedmodel : dict
462+ regcomp : bool, True if we are comparing ART and TDT, False if we are comparing trained and random models
494463
495464 Returns
496465 -------
@@ -531,7 +500,6 @@ def plot_compvp_ee(trainedmodevals, controlmodevals, trainedmodel, regcomp = Fal
531500 patches = []
532501
533502 ccolorindex = 1
534- #for (modevals, cmap, alpha, zorder, lr) in zip([controlmodevals, trainedmodevals], [controlcmap, trainedcmap], [[0.8, 0.5], [0.8, 0.7]], [2,1], ['r', 'l']):
535503 for (modevals , cmap , alpha , zorder , lr ) in zip ([controlmodevals , trainedmodevals ], [controlcmap , trainedcmap ], [[1 , 1 ], [1 , 1 ]], [2 ,1 ], ['r' , 'l' ]):
536504 for i , mod in enumerate (modevals ):
537505
@@ -574,7 +542,6 @@ def plot_compvp_ee(trainedmodevals, controlmodevals, trainedmodel, regcomp = Fal
574542 vp = None
575543
576544
577- #patches.append(mpatches.Patch(color=cmap(cidx[i]), alpha=0.7))
578545 patches .append (mpatches .Patch (color = cmap (cidx [i ]), alpha = 1 ))
579546
580547 vps .append (vp )
0 commit comments