def test_boxplots_with_color(): data = {'group_1':np.random.randn(50), 'group_2':np.random.randn(50)*2, 'group_3':np.random.randn(50)-2} plt.figure() boxplot_with_colors(data, group_names=['group_1', 'group_2', 'group_3'], group_colors=['r', 'g', 'b']) plt.show()
def plot_lfp_and_spike_perf_boxplot(agg, ax=None, lfp_decomp='full_psds'): if ax is None: ax = plt.gca() df = get_lfp_and_spike_perfs_for_boxplot(agg, lfp_decomp=lfp_decomp) freqs, lags = get_freqs_and_lags() bp_data = dict() i = (df.f == -1) & ~np.isnan(df.r2) & (df.r2 > 0) bp_data['Spike\nRate'] = df.r2[i].values for f in freqs: i = (df.f == f) & (df.r2 > 0) & ~np.isnan(df.r2) bp_data['%d' % f] = df.r2[i].values group_names = ['Spike\nRate'] group_names.extend(['%d' % f for f in freqs]) group_colors = [COLOR_RED_SPIKE_RATE] group_colors.extend([COLOR_BLUE_LFP]*len(freqs)) boxplot_with_colors(bp_data, group_names, ax=ax, group_colors=group_colors, box_alpha=0.95) plt.ylim(0, 0.8) plt.ylabel('Encoder R2') plt.xlabel('Frequency (Hz)') xticks = ['Spike\nRate', 'LFP\n(0-30Hz)', 'LFP\n(30-80Hz)', 'LFP\n(80-190Hz)'] plt.xticks(np.arange(len(xticks))+1, xticks)
def test_boxplots_with_color(): data = { 'group_1': np.random.randn(50), 'group_2': np.random.randn(50) * 2, 'group_3': np.random.randn(50) - 2 } plt.figure() boxplot_with_colors(data, group_names=['group_1', 'group_2', 'group_3'], group_colors=['r', 'g', 'b']) plt.show()
def draw_perfs(agg): # filter out some data points i = (agg.df.cc > 0.05) & (agg.df.region != '?') & (agg.df.region != 'HP') \ & ~np.isnan(agg.df.dist_l2a) & ~np.isnan(agg.df.dist_midline) \ & (agg.df.dist_l2a > -1) & (agg.df.dist_l2a < 1) df = agg.df[i] print len(df) print df.region.unique() # make a scatter plot of performance by anatomical location fig = plt.figure(figsize=(23, 10), facecolor='w') fig.subplots_adjust(left=0.05, right=0.95, wspace=0.25, hspace=0.25) gs = plt.GridSpec(2, 100) ax = plt.subplot(gs[:, :55]) plt.scatter(df.dist_midline, df.dist_l2a, c=df.cc, s=64, cmap=plt.cm.afmhot_r, alpha=0.7) plt.ylim(-1, 1) plt.xlim(0, 2.5) for x, y, r in zip(df.dist_midline, df.dist_l2a, df.region): plt.text(x, y - 0.05, r, fontsize=9) cbar = plt.colorbar(label='Linear Encoder Performance (cc)') plt.xlabel('Dist to Midline (mm)') plt.ylabel('Dist to L2A (mm)') region_stats = list() regions_to_use = ['L1', 'L2', 'L3', 'CM', 'NCM'] for reg in regions_to_use: i = df.region == reg region_stats.append({'cc': df[i].cc, 'cc_mean': df[i].cc.mean(), 'region': reg}) region_stats.sort(key=operator.itemgetter('cc_mean'), reverse=True) regions = [x['region'] for x in region_stats] region_ccs = {x['region']: x['cc'] for x in region_stats} ax = plt.subplot(gs[:45, 65:]) boxplot_with_colors(region_ccs, group_names=regions, ax=ax, group_colors=['k'] * len(regions), box_alpha=0.7) plt.xlabel('Region') plt.ylabel('Linear Encoder Performance (cc)') fname = os.path.join(get_this_dir(), 'encoder_perf.svg') plt.savefig(fname, facecolor=fig.get_facecolor(), edgecolor='none')