def plotContrast(exp = "004B", trim=True, inclSim=True,stats=True,norm=False): """ Plots landing positions as a function of contrats manipulation per saccade, for Exp 1 and Exp 2, relative to CoG. Keyword arguments: trim --- (default=True) """ # Get dm: src = 'selected_dm_%s_WITH_drift_corr_onlyControl_False.csv' % exp dm = CsvReader(src).dataMatrix() colList = ["#f57900", "#3465a4"] lLegend = ["Saccade 1", "Saccade 2"] fig = plt.figure(figsize = (3,4)) plt.subplots_adjust(left=.2, bottom=.15) yLim = [-.07, .12] for sacc in ["1", "2"]: dv = "endX%sNorm" % sacc saccVar = "saccLat%s" % sacc # Get dm: # Only on-object: dm = onObject.onObject(dm, sacc,verbose=False) if trim: dm = dm.removeField("__dummyCond__") dm = dm.removeField("__stdOutlier__") dm = dm.selectByStdDev(keys = ["file"], \ dv = dv,verbose=False) dm = dm.removeField("__dummyCond__") dm = dm.removeField("__stdOutlier__") dm = dm.selectByStdDev(keys = ["file"], dv = saccVar,\ verbose=False) # Collect mean and error bar per saccade: lM = [] lErr = [] if norm: # Normalize across handle side: dm = dm.removeField("normDV") dm= dm.addField("normDV", dtype = float) dm= dm.withinize(dv, "normDV", \ ["handle_side"], whiten=False) dv = "normDV" for contrast in dm.unique("contrast_side"): contrast_dm = dm.select("contrast_side == '%s'" % contrast,\ verbose = False) cm = contrast_dm.collapse(["file"], dv) M = cm["mean"].mean() SE = cm['mean'].std() / np.sqrt(len(cm)) CI = SE * critVal lM.append(M) lErr.append(CI) if stats: # Run a full LME print "Exp = ", exp print "DV = ", dv print "trim = ", trim print "norm = ", norm print "saccVar = ", saccVar lmeContrast(R, dm, dv, saccVar, exp=exp) #raw_input() xData = range(len(lM)) yData = lM yErr = lErr col = colList.pop() plt.errorbar(xData, yData, yerr=yErr, fmt='o-', marker = "o", \ color = col, markerfacecolor='white', markeredgecolor=col, \ markeredgewidth=1) plt.axhline(0, linestyle = "--") plt.ylim(yLim) plt.ylabel(yTitle) #ax.yaxis.set_ticklabels([]) plt.legend(lLegend, frameon = False) plt.axhline(0, color = "black", linestyle = "--") plt.xlabel("High-contrast side") spacing = 0.5 xTicks = range(0,3) xLabels = ["Left", "Control", "Right"] plt.xticks(xTicks, xLabels, rotation = .5) plt.xlim(min(xTicks)-spacing, max(xTicks)+spacing) plt.savefig(os.path.join(dst,"Contrast_Effect_%s_trim_%s_norm_%s.png") \ % (exp, trim, norm)) plt.show()
def plotGap(exp, dv = "saccLat1", trim = False, norm=True, nBins = 50, \ exclFastSacc = False): """ """ src = 'selected_dm_%s_WITH_drift_corr_onlyControl_True.csv' % exp dm = CsvReader(src).dataMatrix() # Determine sacc: sacc = [int(x.group()) for x in re.finditer(r'\d+', dv)][0] dm = onObject.onObject(dm, sacc) # Exclude very fast saccades: dm = dm.select("%s > 80" % dv) colList = [orange[1], blue[1]] # Trim the data if trim: dm = dm.removeField("__dummyCond__") dm = dm.removeField("__stdOutlier__") dm = dm.selectByStdDev(["file"], dv, \ verbose=False) dm = dm.removeField("__dummyCond__") dm = dm.removeField("__stdOutlier__") dm = dm.selectByStdDev(["file"], "endX%sNormToHandle" % sacc, \ verbose=False) if exp == "004A": dm = dm.removeField("__dummyCond__") dm = dm.removeField("__stdOutlier__") dm = dm.selectByStdDev(["file"], "endX%sCorrNormToHandle" % sacc, \ verbose=False) else: dm = dm.select("%s < 1000" % dv) # Normalize saccade latencies if norm: dm= dm.addField("normSacc", dtype = float) dm= dm.withinize(dv, "normSacc", \ ["file"], whiten=False) dv = "normSacc" for gap in dm.unique("gap"): _dm = dm.select("gap == '%s'" % gap) samp = _dm[dv] y, edges = np.histogram(samp, bins = nBins) y = normY(y) x = .5*edges[1:] + .5*edges[:-1] col = colList.pop() plt.plot(x, y, color = col) plt.fill_between(x, 0, y, alpha=.3, color=col) plt.legend(dm.unique("gap")) plt.ylim([0,1.1])