In [1]:
% matplotlib inline
import numpy
import seaborn
import matplotlib.pyplot as plt
import os
import numpy as np
import pandas as pd
import palettable.colorbrewer as cb
In [2]:
lines=[i.strip().split(',') for i in open('es.csv').readlines()]
task=[]
region=[]
roisize=[]
cohend=[]
pctsig=[]
desc=[]
for i in range(len(lines)):
task.append(lines[i][0])
region.append(lines[i][1])
desc.append(lines[i][0]+': '+lines[i][1])
roisize.append(int(lines[i][2]))
cohend.append([float(j) for j in lines[i][3:6]])
pctsig.append([float(j) for j in lines[i][6:9]])
In [3]:
cohen = []
percent = []
condition = []
conn = []
for i in range(len(task)):
CD = [float(x.strip()) for x in open(os.path.join("EffectSize",'cohensd_'+task[i]+"_"+region[i]+".csv"))]
cohen = cohen+CD
PB = [float(x.strip()) for x in open(os.path.join("EffectSize",'percent_'+task[i]+"_"+region[i]+".csv"))]
percent = percent+PB
des = str(task[i])+": "+str(region[i]+" ("+str(roisize[i])+")")
conn = conn+np.repeat(i,len(PB)).tolist()
condition = condition+np.repeat(des,len(PB)).tolist()
In [4]:
Effect = {}
Effect['cohen']=pd.Series(cohen)
Effect['percent']=pd.Series(percent)
Effect['condition']=pd.Series(condition)
Effect['conn']=pd.Series(conn)
Effect = pd.DataFrame(Effect)
Effect[1:10]
Out[4]:
In [5]:
print("CHECK IF COHENS D ARE SAME AS IN TABLE")
print("\n")
for i in range(len(task)):
ind = [Effect['cohen'][ind] for ind, x in enumerate(conn) if x==i]
med = np.nanmedian(ind)
print(task[i]+"_"+region[i]+": median = "+str(med))
print("\n")
print("CHECK IF PERCENTAGES ARE SAME AS IN TABLE")
print("\n")
for i in range(len(task)):
ind = [Effect['percent'][ind] for ind, x in enumerate(conn) if x==i]
med = np.nanmedian(ind)
print(task[i]+"_"+region[i]+": median = "+str(med))
In [6]:
cols = cb.qualitative.Set2_8.mpl_colors
plt.figure(1,figsize=(10,10))
plt.subplot(2,2,1)
ax = seaborn.violinplot(x="percent", y="condition",cut=0,
inner = 'box',color=cols[0],
data=Effect,scale='width',width=0.8,
linewidth=1,sharex=False,sharey=False)
ax.set(xlim=(-2,30))
ax.set_xlabel("% BOLD change")
ax.set_ylabel("")
plt.subplot(2,2,2)
ax2 = seaborn.violinplot(x="cohen", y="condition",cut=0,
inner='box',color=cols[1],
data=Effect,scale='width',widht=0.8,
linewidth=1,sharex=False,sharey=False)
ax2.set(xlim=(-0.5,2.1))
ax2.yaxis.set_visible(False)
ax2.set_xlabel("Cohen's D")
plt.savefig('Figure1.pdf',bbox_inches='tight')