def time_course(source=False, make_tight=True, make_sem=True, show=["emotion", "scrambled", "rt_em", "rt_sc"], sample_by=4, fontscale=1, force_new=False): rt = get_rt_data(make_categories=categories) all_timecourses = get_et_data(make='timecourse', make_categories=categories, savefile='time_series.csv', baseline="participant", force_new=force_new) all_timecourses["Time"] = all_timecourses["Time"]/1000 #make seconds (from milliseconds) all_timecourses.to_csv("/home/chymera/TC_all.csv") all_timecourses = all_timecourses.reset_index(drop=False) all_timecourses = all_timecourses.set_index(["CoI","measurement"], append=True, drop=True) all_timecourses = all_timecourses.reset_index(level=0,drop=True) #downsamples the timecourse: timecourse_plot = all_timecourses.groupby(level=0).apply(downsample, sample=sample_by, group='measurement') #BEGI SEMS SEM_timecourse_normed = all_timecourses.groupby(level=(0,1)).aggregate(sem) SEM_timecourse_plot = SEM_timecourse_normed.groupby(level=0).apply(downsample, sample=sample_by, group='measurement') ###END SEMS timecourse_plot = timecourse_plot.reset_index(level=1) SEM_timecourse_plot = SEM_timecourse_plot.reset_index(level=1) #BEGIN PLOTTING fig = figure(figsize=(5, 3), dpi=300,facecolor='#eeeeee', tight_layout=make_tight) ax1=fig.add_subplot(1,1,1,axisbg='1') ax1.yaxis.grid(True, linestyle='-', which='major', color='#dddddd',alpha=0.6, zorder = 0) ax1.set_axisbelow(True) plotted = [] plotted_names = [] if "fix" in show: if make_sem: ax1.fill_between(np.array(timecourse_plot.ix["fix"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["fix"]["Pupil"]+SEM_timecourse_plot.ix["fix"]["Pupil"]/2), np.array(timecourse_plot.ix["fix"]["Pupil"]-SEM_timecourse_plot.ix["fix"]["Pupil"]/2), facecolor="0.8", edgecolor="none", alpha=0.2, zorder=0) ax1.plot(np.array(timecourse_plot.ix["fix"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["fix"]["Pupil"]), color="0.8",zorder=2) fix = Rectangle((0, 0), 1, 1, color="0.8") plotted.append(fix) plotted_names.append("Fixation") if "easy" in show: if make_sem: ax1.fill_between(np.array(timecourse_plot.ix["easy"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["easy"]["Pupil"]+SEM_timecourse_plot.ix["easy"]["Pupil"]/2), np.array(timecourse_plot.ix["easy"]["Pupil"]-SEM_timecourse_plot.ix["easy"]["Pupil"]/2), facecolor="g", edgecolor="none", alpha=0.1, zorder=0) ax1.plot(np.array(timecourse_plot.ix["easy"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["easy"]["Pupil"]), color='g',zorder=2) easy = Rectangle((0, 0), 1, 1, color="g") plotted.append(easy) plotted_names.append("Easy Trials") if "hard" in show: if make_sem: ax1.fill_between(np.array(timecourse_plot.ix["hard"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["hard"]["Pupil"]+SEM_timecourse_plot.ix["hard"]["Pupil"]/2), np.array(timecourse_plot.ix["hard"]["Pupil"]-SEM_timecourse_plot.ix["hard"]["Pupil"]/2), facecolor="m", edgecolor="none", alpha=0.1, zorder=0) ax1.plot(np.array(timecourse_plot.ix["hard"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["hard"]["Pupil"]), color='m',zorder=2) hard = Rectangle((0, 0), 1, 1, color="m") plotted.append(hard) plotted_names.append("Hard Trials") if "happy" in show: if make_sem: ax1.fill_between(np.array(timecourse_plot.ix["happy"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["happy"]["Pupil"]+SEM_timecourse_plot.ix["happy"]["Pupil"]/2), np.array(timecourse_plot.ix["happy"]["Pupil"]-SEM_timecourse_plot.ix["happy"]["Pupil"]/2), facecolor="g", edgecolor="none", alpha=0.1, zorder=0) ax1.plot(np.array(timecourse_plot.ix["happy"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["happy"]["Pupil"]), color='g',zorder=2) happy = Rectangle((0, 0), 1, 1, color="g") plotted.append(happy) plotted_names.append("'Happy' Trials") if "fearful" in show: if make_sem: ax1.fill_between(np.array(timecourse_plot.ix["fearful"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["fearful"]["Pupil"]+SEM_timecourse_plot.ix["fearful"]["Pupil"]/2), np.array(timecourse_plot.ix["fearful"]["Pupil"]-SEM_timecourse_plot.ix["fearful"]["Pupil"]/2), facecolor="m", edgecolor="none", alpha=0.1, zorder=0) ax1.plot(np.array(timecourse_plot.ix["fearful"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["fearful"]["Pupil"]), color='m',zorder=2) fearful = Rectangle((0, 0), 1, 1, color="m") plotted.append(fearful) plotted_names.append("'Fearful' Trials") if "emotion" in show: tc = (np.array(timecourse_plot.ix["fearful"]["measurement"])/(60/sample_by)+np.array(timecourse_plot.ix["happy"]["measurement"])/(60/sample_by))/2 v = (np.array(timecourse_plot.ix["fearful"]["Pupil"])+np.array(timecourse_plot.ix["happy"]["Pupil"]))/2 if make_sem: se = (np.array(SEM_timecourse_plot.ix["fearful"]["Pupil"])+np.array(SEM_timecourse_plot.ix["happy"]["Pupil"]))/4 ax1.fill_between(tc, v+se, v-se, facecolor="g", edgecolor="none", alpha=0.1, zorder=0) ax1.plot(tc, v, color='g',zorder=2) emotion = Rectangle((0, 0), 1, 1, color="g") plotted.append(emotion) plotted_names.append("Emotion Trials") if "scrambled" in show: if make_sem: ax1.fill_between(np.array(timecourse_plot.ix["scrambled"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["scrambled"]["Pupil"]+SEM_timecourse_plot.ix["scrambled"]["Pupil"]/2), np.array(timecourse_plot.ix["scrambled"]["Pupil"]-SEM_timecourse_plot.ix["scrambled"]["Pupil"]/2), facecolor="m", edgecolor="none", alpha=0.1, zorder=0) ax1.plot(np.array(timecourse_plot.ix["scrambled"]["measurement"])/(60/sample_by), np.array(timecourse_plot.ix["scrambled"]["Pupil"]), color='m',zorder=2) scrambled = Rectangle((0, 0), 1, 1, color="m") plotted.append(scrambled) plotted_names.append("Scrambled Trials") if "all" in show: all_tc = (np.array(timecourse_plot.ix["easy"]["measurement"])/(60/sample_by)+np.array(timecourse_plot.ix["hard"]["measurement"])/(60/sample_by))/2 all_v = (np.array(timecourse_plot.ix["easy"]["Pupil"])+np.array(timecourse_plot.ix["hard"]["Pupil"]))/2 if make_sem: all_se = (np.array(SEM_timecourse_plot.ix["easy"]["Pupil"])+np.array(SEM_timecourse_plot.ix["hard"]["Pupil"]))/4 ax1.fill_between(all_tc, all_v+all_se, all_v-all_se, facecolor="g", edgecolor="none", alpha=0.1, zorder=0) ax1.plot(all_tc, all_v, color='g',zorder=2) ALL = Rectangle((0, 0), 1, 1, color="g") plotted.append(ALL) plotted_names.append("All Trials") if "rt_e" in show: ax1.axvline(rt[(rt["difficulty"] == "easy")]["RT"].mean(), linewidth=0.3, color='g', zorder=1) if "rt_h" in show: ax1.axvline(rt[(rt["difficulty"] == "hard")]["RT"].mean(), linewidth=0.3, color='m', zorder=1) if "rt_ha" in show: ax1.axvline(rt[(rt["emotion"] == "happy")]["RT"].mean(), linewidth=0.3, color='g', zorder=1) if "rt_fe" in show: ax1.axvline(rt[(rt["emotion"] == "fearful")]["RT"].mean(), linewidth=0.3, color='m', zorder=1) if "rt_em" in show: ax1.axvline(rt[(rt["emotion"] != "scrambled")]["RT"].mean(), linewidth=0.3, color='g', zorder=1) if "rt_sc" in show: ax1.axvline(rt[(rt["emotion"] == "scrambled")]["RT"].mean(), linewidth=0.3, color='m', zorder=1) if "rt_all" in show: ax1.axvline(rt[(rt["difficulty"] == "easy") | (rt["difficulty"] == "hard")]["RT"].mean(), linewidth=0.3, color='g', zorder=1) ax1.tick_params(axis='both', labelsize=8*fontscale) ax1.set_ylabel('Pupil Area Ratio', fontsize=11*fontscale) ax1.set_xlabel('Time [s]', fontsize=11*fontscale) legend((plotted),(plotted_names),loc='upper center', bbox_to_anchor=(0.5, 1.06), ncol=3, fancybox=False, shadow=False, prop=FontProperties(size=str(9*fontscale))) #END PLOTTING return all_timecourses
def main(make=False, source=False, make_tight=True, conditions=conditions, show="", make_std=False, make_sem=True, ecolor='0.3', elinewidth=2, total="means", make_scrambled_yn=False, fontscale=1): data_all = get_rt_data(make_categories=categories) ids = sorted(list(data_all.index.levels[0])) pos_ids = np.arange(len(ids)) fig = figure(figsize=(pos_ids.max()*5, 4), dpi=300,facecolor='#eeeeee', tight_layout=make_tight) ax=fig.add_subplot(1,1,1) ax.yaxis.grid(True, linestyle='-', which='major', color='#dddddd',alpha=0.6, zorder = 0) ax.set_axisbelow(True) width = 0.12 data_all.reset_index(inplace=True) total_errors_columns = ['ID', 'ER'].extend([condition[0][0] for condition in conditions]) total_errors = pd.DataFrame(columns=total_errors_columns) # empty container frame for concatenating input from multiple files for le_id in set(data_all['ID']): data_for_id = data_all[data_all['ID'] == le_id] for C in product(conditions[0], conditions[1]): error_rate = len(data_for_id[(data_for_id[C[0][0]] == C[0][1]) & (data_for_id[C[1][0]] == C[1][1]) & (data_for_id['Type'] == "incorrect")].index)/len(data_for_id[(data_for_id[C[0][0]] == C[0][1]) & (data_for_id[C[1][0]] == C[1][1]) & (data_for_id['Type'] == "hit")].index) row = pd.DataFrame({"ID":[le_id], "ER":[error_rate], C[0][0]:[C[0][1]], C[1][0]:[C[1][1]]}) total_errors = total_errors.append(row, ignore_index=True) #ADD ID total_errors = total_errors.set_index(['ID'], append=True, drop=True) total_errors = total_errors.reorder_levels([1,0]) #END ADD ID if make_scrambled_yn: total_errors["scrambled"]="" total_errors.ix[(total_errors["emotion"] == "scrambled"), "scrambled"]= "yes" total_errors.ix[(total_errors["emotion"] != "scrambled"), "scrambled"]= "no" total_errors_just_plot = total_errors.copy() # please DO NOT USE THE DATA FROM THIS NEW VARIABLE for anything BUT plotting total_errors_just_plot.ix[(total_errors_just_plot['ER'] == 0), 'ER'] = 0.005 # this is a hack to make 0-height bins visible when plotting #START DRAWING GRAPHIC ELEMENTS #below this: per-participant graphs plot_em_easy = plt.bar(pos_ids-2*width, total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "easy")].groupby(level=0)['ER'].mean(), width ,color='m', alpha=0.7, zorder = 1, linewidth=0) plot_em_hard = plt.bar(pos_ids-width, total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "hard")].groupby(level=0)['ER'].mean(), width ,color='m', alpha=0.4, zorder = 1, linewidth=0) plot_sc_easy = plt.bar(pos_ids, total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "easy")].groupby(level=0)['ER'].mean(), width ,color="g", alpha=0.7, zorder = 1, linewidth=0) plot_sc_hard = plt.bar(pos_ids+width, total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "hard")].groupby(level=0)['ER'].mean(), width ,color="g", alpha=0.4, zorder = 1, linewidth=0) #below this: total graphs plt.bar(pos_ids[-1]+1-width, total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]['ER'].mean(), width ,color='m', alpha=0.7, zorder = 1, linewidth=0) plt.bar(pos_ids[-1]+1, total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]['ER'].mean(), width ,color='m', alpha=0.4, zorder = 1, linewidth=0) plt.bar(pos_ids[-1]+1+width, total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]['ER'].mean(), width ,color='g', alpha=0.7, zorder = 1, linewidth=0) plt.bar(pos_ids[-1]+1+2*width, total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"].mean(), width ,color='g', alpha=0.4, zorder = 1, linewidth=0) if make_std: errorbar(pos_ids[-1]+1-(width/2), total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]['ER'].mean(), yerr=np.std(total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]['ER']), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width/2), total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"].mean(), yerr=np.std(total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"]), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*1.5), total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]["ER"].mean(), yerr=np.std(total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]["ER"]), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*2.5), total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"].mean(), yerr=np.std(total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"]), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) if make_sem: errorbar(pos_ids[-1]+1-(width/2), total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]["ER"].mean(), yerr=sem(total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]["ER"]), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width/2), total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"].mean(), yerr=sem(total_errors_just_plot[(total_errors_just_plot['emotion'] != "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"]), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*1.5), total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]["ER"].mean(), yerr=sem(total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "easy")]["ER"]), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*2.5), total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"].mean(), yerr=sem(total_errors_just_plot[(total_errors_just_plot['emotion'] == "scrambled") & (total_errors_just_plot['difficulty'] == "hard")]["ER"]), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) width_multiplier = 4 plt.axvline(pos_ids[-1]+1-width*width_multiplier, color='0.2') #separator - per-person/total ids=ids+[' ALL'] pos_ids = np.arange(len(ids)) ax.set_ylabel(r'$\mathsf{\Sigma_{wrong} / \Sigma_{all}}$', fontsize=13*fontscale) ax.set_xlabel('Participant', fontsize=11*fontscale) ax.set_xticks(pos_ids) ax.set_xticklabels(ids,fontsize=9*fontscale) # add rotation=30 if things get too crowded for tick in ax.axes.get_xticklines(): tick.set_visible(False) ax.set_xlim(0, pos_ids[-1]+width*1) # before scaling to add padding in front of zero axis.Axis.zoom(ax.xaxis, -0.8) # sets x margins further apart from the content proportional to its length axis.Axis.zoom(ax.yaxis, -0.5) # sets y margins further apart from the content proportional to its length ax.set_ylim(bottom=0) # after scaling to disregard padding unerneath zero. legend((plot_em_easy, plot_em_hard, plot_sc_easy, plot_sc_hard),('Strong Emotion','Weak Emotion', "Easy Scrambling", "Hard Scrambling"),loc='upper center', bbox_to_anchor=(0.5, 1.065), ncol=4, fancybox=False, shadow=False,prop= FontProperties(size=str(8*fontscale))) return total_errors
def main(make=False, source=False, make_tight=True, compare="difficulty", show="", make_std=True, make_sem=True, ecolor='0.3', elinewidth=2, total="means", make_scrambled_yn=False, fontscale=1): data_all = get_rt_data(make_categories=categories, make_scrambled_yn=make_scrambled_yn) ids = sorted(list(data_all.index.levels[0])) pos_ids = np.arange(len(ids)) fig = figure(figsize=(pos_ids.max()*5, 4), dpi=300,facecolor='#eeeeee', tight_layout=make_tight) ax=fig.add_subplot(1,1,1) ax.yaxis.grid(True, linestyle='-', which='major', color='#dddddd',alpha=0.6, zorder = 0) ax.set_axisbelow(True) width = 0.12 #below this: per-participant graphs plot_em_easy = plt.bar(pos_ids-2*width, data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean(), width ,color='m', alpha=0.7, zorder = 1, linewidth=0) plot_em_hard = plt.bar(pos_ids-width, data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean(), width ,color='m', alpha=0.4, zorder = 1, linewidth=0) plot_sc_easy = plt.bar(pos_ids, data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean(), width ,color="g", alpha=0.7, zorder = 1, linewidth=0) plot_sc_hard = plt.bar(pos_ids+width, data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean(), width ,color="g", alpha=0.4, zorder = 1, linewidth=0) if make_std: errorbar(pos_ids-(width*1.5), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].aggregate(np.std), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids-(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].aggregate(np.std), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids+(width*0.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].aggregate(np.std), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids+(width*1.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].aggregate(np.std), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) if make_sem: errorbar(pos_ids-(width*1.5), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].aggregate(sem), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids-(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].aggregate(sem), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids+(width*0.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].aggregate(sem), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids+(width*1.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean(), yerr=data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].aggregate(sem), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) #below this: total graphs plt.bar(pos_ids[-1]+1-width, data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), width ,color='m', alpha=0.7, zorder = 1, linewidth=0) plt.bar(pos_ids[-1]+1, data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), width ,color='m', alpha=0.4, zorder = 1, linewidth=0) plt.bar(pos_ids[-1]+1+width, data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), width ,color='g', alpha=0.7, zorder = 1, linewidth=0) plt.bar(pos_ids[-1]+1+2*width, data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), width ,color='g', alpha=0.4, zorder = 1, linewidth=0) if total == 'all': if make_std: errorbar(pos_ids[-1]+1-(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")]['RT']), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")]['RT']), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*1.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")]['RT']), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*2.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")]['RT']), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) if make_sem: errorbar(pos_ids[-1]+1-(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")]['RT']), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")]['RT']), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*1.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")]['RT']), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*2.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")]['RT']), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) elif total == 'means': if make_std: errorbar(pos_ids[-1]+1-(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean()), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean()), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*1.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean()), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*2.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=np.std(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean()), ecolor=str(float(ecolor)+0.25), elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) if make_sem: errorbar(pos_ids[-1]+1-(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean()), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width/2), data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] != "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean()), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*1.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "easy")].groupby(level=0)['RT'].mean()), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) errorbar(pos_ids[-1]+1+(width*2.5), data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")]['RT'].mean(), yerr=sem(data_all[(data_all['emotion'] == "scrambled") & (data_all['difficulty'] == "hard")].groupby(level=0)['RT'].mean()), ecolor=ecolor, elinewidth=elinewidth, capsize=0, linestyle='None', zorder = 2) width_multiplier = 4 plt.axvline(pos_ids[-1]+1-width*width_multiplier, color='0.2') #separator - per-person/total #~ scrambling_list = [str(i) for i in scrambling_list if i != 0] #format as string for legend #~ ids=ids+[' ALL'] pos_ids = np.arange(len(ids)) ax.set_ylabel(r'$\mathsf{\overline{RT}}$ [s]', fontsize=11*fontscale) ax.set_xlabel('Participant', fontsize=11*fontscale) ax.set_xticks(pos_ids) ax.set_xticklabels(ids, fontsize=9*fontscale) # add rotation=30 if things get too crowded for tick in ax.axes.get_xticklines(): tick.set_visible(False) ax.set_xlim(0, pos_ids[-1]+width*1) # before scaling to add padding in front of zero axis.Axis.zoom(ax.xaxis, -0.8) # sets x margins further apart from the content proportional to its length axis.Axis.zoom(ax.yaxis, -0.5) # sets y margins further apart from the content proportional to its length ax.set_ylim(bottom=0) # after scaling to disregard padding unerneath zero. legend((plot_em_easy, plot_em_hard, plot_sc_easy, plot_sc_hard),('Strong Emotion','Weak Emotion', "Easy Scrambling", "Hard Scrambling"),loc='upper center', bbox_to_anchor=(0.5, 1.065), ncol=4, fancybox=False, shadow=False, prop=FontProperties(size=str(8*fontscale))) return data_all