def plotSkew(dgps): global FII cls=['$c_l$','$b$','$c_l$','$c_l$','$c_l$','$c_l$'] figure(size=3,aspect=0.6) for h in range(len(dgps)): try:D=dgps[h].loadData(i=2,j=2) except FileNotFoundError: continue x=dgps[h].cl for g in range(3): ax=subplot(3,len(dgps),1+h+g*len(dgps)) plt.grid(axis='x') if g==0: plt.title(DLBLS[h]) y=np.median(D[:,:,6],axis=1)*[1,0.1][dgps[h].suf=='BE'] elif g==1: y=np.median(D[:,:,7],axis=1) elif g==2: y=np.median(D[:,:,23],axis=1) plt.plot(x,y,CLRS[-1],lw=LWS[1]) if g==0: plt.ylim([0,1]) elif g==1: plt.ylim([[0,10],[0,0.01],[0,3],[0,6],[0,0.1],[0,0.06]][h]) elif g==2: plt.ylim([[0,3],[0,3],[0,8],[0,3],[0,3],[-3,3]][h]) if g<2: ax.set_xticklabels([]) else: plt.xlabel(cls[h]) plt.xlim([x[0],x[-1]]) ax.locator_params(axis='x', nbins=4,min_n_ticks=3) if not h: plt.ylabel(['Mean','Variance','Skewness'][g]) elif g==0: ax.set_yticklabels([]) elif g==1: lm=[0,-3,0,0,-2,-2][h] if lm!=0: ax.ticklabel_format(axis='y',style='sci',scilimits=(lm,lm)) if FII>=0: fn='fig%02d.%s'%(FII,FIGFMT) FII+=1 else: fn=FIGLBLS[0]+'png' plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI,format=FIGFMT) plt.clf();plt.close()
def plotPDF(A,B,C,pdf,xmax=1,albls=['','','test']): C=np.linspace(C[0],C[-1],6) x=np.linspace(0,xmax,101) figure(size=3,aspect=1) def _hlp(A,i): if A.size>1 and xmax>0: return '%.2f'%A[i] else: return '' for i in range(A.size): for j in range(B.size): for h in range(C.size): ax=subplot(A.size,B.size,B.size*i+1+j) try: if xmax>0: y=pdf(x,A[i],B[j],C[h]) else: y,x=pdf(A[i],B[j],C[h]) except AssertionError: continue plt.plot(x,y,'k',alpha=0.2) plt.ylim([0,1]) ax.set_yticks([0,1]) if j>0: ax.set_yticklabels([]) else: plt.ylabel(albls[0]+_hlp(A,i)) if i+1<A.size: ax.set_xticklabels([]) else: plt.xlabel(albls[1]+_hlp(B,j)) plt.grid(False) plt.savefig(SUPDIR+albls[-1]+'prob',format=FIGFMT, bbox_inches='tight',dpi=DPI) plt.clf();plt.close()
def plotXtypes(S): global FII figure(size=2,aspect=0.4) lbls=['No X','Ballanced','Uncrossed','Crossed','Double-crossed'] for i in range(5): s=S[i+2] ax=subplot(1,5,i+1) plt.plot([0,1],s[:2],'-o') plt.plot([0,1],s[2:],'-o') ax.set_xticks([0,1]) ax.set_xticklabels(['G1','G2']) plt.ylim([-4.5,0.5]) plt.xlim([-0.25,1.25]) if i>0: ax.set_yticklabels([]) else: #plt.legend(['F1','F2']) plt.ylabel('$d$') plt.xlabel(lbls[i]) if FII>=0: fn='fig%02d.%s'%(FII,FIGFMT) FII+=1 else: fn='xtypes.png' plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI,format=FIGFMT) plt.clf() plt.close()
def plotBrief(x,R,y=np.nan,pref='', ylim=[[],[]]): global FII figure(size=2,aspect=1.2) for f in range(1,7): ax=subplot(3,2,f); plt.grid(axis='x') plt.ylim([-0.02,1.02]) plt.title(['CI','Cohen\'s $d$','TOST','Bayesian $t$ test','Two-group tests','Three-group tests'][f-1]) if f==1: plotCI(x,R) #if np.any(~np.isnan(y)): plt.plot(x,y,'c') plt.ylim(ylim[0]) elif f==2: plotCohendCI(x,R) plt.ylim(ylim[1]) elif f==3: plotTOST(x,R[:,:,12:16]) elif f==4: plotBFT(x,R[:,:,16:18]) elif f==5: plotNHST(x,R[:,:,8:12]) elif f==6: plotANOVA1F(x,R[:,:,18:21]) if f<5: ax.set_xticklabels([]) else: plt.xlabel(['$c_l$','$b$'][int(pref=='W')]) plt.xlim([x[0],x[-1]]) if FII>=0: fn='fig%02d.%s'%(FII,FIGFMT) FII+=1 else: fn=pref+'brief.png' plt.savefig(FIGDIR+fn,dpi=DPI,bbox_inches='tight',format=FIGFMT)
def plot(figname='stan.png', dpi=300): from matusplotlib import figure, subplot, plt figure(size=3, aspect=0.3) il = [ 'dog', 'trolley', 'wallet', 'plane', 'resume', 'kitten', 'mean score', 'median score' ] w = loadStanFit('schnall') S = np.load('S.npy') offset = np.array(w['c'][:, 0] / 2 + w['c'][:, -1] / 2, ndmin=2).T scale = np.array(np.abs(w['c'][:, 0] - w['c'][:, -1]) / 2, ndmin=2).T bp = np.linspace(-2.2, 2.2, 51) b = bp * np.median(scale) + np.median(offset) cs = np.median(w['c'], axis=0) d = np.median(-w['d'], axis=0) #xlm=[cs[0]-0.2,cs[-1]+0.2] xlm = b[[0, -1]] cls = [] for i in range(cs.size): cls.append('$c_%d$' % i) tmp = np.median(-w['tbeta'], axis=0) for j in range(2): ax = subplot(1, 2, 1 + j) plt.plot(xlm, [-d[0], -d[0]]) plt.xlim(xlm) ax.set_xticks(cs) ax.set_xticklabels(cls) plt.plot(tmp[0, :], -0.7 * np.ones(6), 'xg') plt.plot(tmp[1, :], -0.9 * np.ones(6), 'xr') #for k in range(tmp.shape[1]): # plt.plot(tmp[0:,k],[-0.09,-0.11],'k',alpha=0.2) ds = np.zeros((len(S), 3)) * np.nan for i in range(len(S)): if j: wi = loadStanFit('schnSimBB%02d' % i) ds[i, :] = sap(wi['gg1'][:, 1] - wi['gg2'][:, 1], [2.5, 50, 97.5]) elif j == 0: wi = loadStanFit('schnSimOLR%02d' % i) ds[i, :] = sap(wi['d'], [2.5, 50, 97.5]) plt.plot(b, ds[:, 1], 'k') temp = [list(b) + list(b)[::-1], list(ds[:, 0]) + list(ds[:, 2])[::-1]] ax.add_patch( plt.Polygon(xy=np.array(temp).T, alpha=0.2, fc='k', ec='k')) plt.ylim([[-2, 4], [-2, 4]][j]) plt.ylabel('$c_u^\Delta$') plt.xlabel(['$c_u=-c_l$', '$c_u$'][j]) plt.title(['OLRM', 'Beta-Binomial'][j]) plt.grid(axis='x') plt.savefig(figname, bbox_inches='tight', dpi=dpi)
def makeSupplement(self): print(self.suf+'creating supplement') #plotPDF(self.np1,self.np2,self.cl,self.pdf,xmax=self.xmax, # albls=['$c_l^\Delta=$','$%s=$'%self.np2lbl,self.suf]) #tref=(self.cld[0,1]-self.cld[0,0])*np.ones(self.cl.shape) n1=self.np1.size;n2=self.np2.size for f in range(1,7): plt.close('all') figure(num=f+1,size=3,aspect=1) for i in range(n1): for j in range(n2): R=self.loadData(i=i,j=j) ax=subplot(n1,n2,i*n2+j+1) #plt.title(getTitle(i,j)) plt.grid(axis='x') plt.ylim([-0.05,1.05]) x=np.load(DPATH+'cl_'+self.suf+'.npy') legon= (i==0 and j==0) if f==1: plotCI(x,R) tref=(self.cld[0,1]-self.cld[0,0])*self.np1[i] plt.plot(x,tref*np.ones(x.size),'c') plt.ylim(self.cil[i]) elif f==2: plotCohendCI(x,R,ylim=self.cil[i+5]) elif f==3:plotNHST(x,R[:,:,8:12],legon) elif f==4:plotANOVA1F(x,R[:,:,18:22],legon) elif f==5:plotTOST(x,R[:,:,12:16],legon) elif f==6:plotBFT(x,R[:,:,16:18],legon) plt.xlim([x[0],x[-1]]) if j!=0:ax.set_yticklabels([]) else:plt.ylabel('$c_l^\Delta=%.2f$'%self.np1[i]) if i!=n1-1: ax.set_xticklabels([]) else: temp=(self.np2lbl,self.np2[j]) plt.xlabel('$%s=%.2f$'%temp) plt.savefig(SUPDIR+self.suf+FIGLBLS[f], dpi=DPI,bbox_inches='tight',format=FIGFMT) plt.clf();plt.close()
def plotFcfe(): global FII figure(size=1,aspect=0.6) x=np.linspace(0,1,101)[1:-1] fl=[-np.log(x),-np.log(x/(1-x))] fu=[-np.log(1-x),-np.log((1-x)/x)] for i in range(2): ax=subplot(1,2,1+i) plt.plot(x,fl[i]) plt.plot(x,fu[i]) plt.xlabel('$g[\phi]$') #if not i:plt.ylabel('$f(\phi)$') plt.text(0.25,3,'$f_l(g)$',horizontalalignment='center') plt.text(0.65,4.1,'$f_u(1-g)$',horizontalalignment='center') ttl=['$-\log x$','$-\log(x/(1-x))$'][i] #plt.legend(['$f_l(\phi)$','$f_u(1-\phi)$']) plt.title(ttl,fontsize=10) if FII>=0: fn='fig%02d.%s'%(FII,FIGFMT) FII+=1 else: fn='fcfe.png' plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI) plt.clf();plt.close()
def plotANOVAall(dgps,showLegend=False,alpha=0.05,i=2,j=2): global FII cls=['$c_l$','$b$','$c_l$','$c_l$','$c_l$','$c_l$'] lblls=['no X','no ME','uncrossed','crossed', 'double-crossed','no X','uncrossed'] K=len(S)-4 figure(size=3,aspect=1) for h in range(len(dgps)): D=dgps[h].loadData(i=i,j=j)[:,:,AI:] x=dgps[h].cl for k in range(K): ax=subplot(K,len(dgps),1+k*len(dgps)+h) plt.grid(axis='x') for ii in range(3): s=np.all(~np.isnan(D[:,:,k*9]),axis=1) if not k: plt.title(DLBLS[h]) plt.plot(x[s],(D[s,:,k*9+ii*3+2]<alpha).mean(1), CLRS[ii],lw=LWS[ii],alpha=0.7) if k<5: plt.plot(x[s],(D[s,:,k*9+ii*3+1]<alpha).mean(1), CLRS[ii]+'--',alpha=0.7,lw=LWS[ii]) plt.plot(x[s],(D[s,:,k*9+ii*3]<alpha).mean(1), CLRS[ii]+':',alpha=0.7,lw=LWS[ii]) if not h: plt.ylabel(lblls[k]) else:ax.set_yticklabels([]) if k<K-1:ax.set_xticklabels([]) else: plt.xlabel(cls[h]) plt.ylim([-0.05,1.05]) plt.xlim([x[0],x[-1]]) plt.locator_params(axis='x', nbins=4)#,min_n_ticks=3) if FII>=0: fn='fig%02d.%s'%(FII,FIGFMT) FII+=1 else: fn='ANOVA%d%d.png'%(i,j) plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI,format=FIGFMT)