def scatterCorr(arrayA, arrayB, threshold, outPath):
"""
Interpretation of strength of correlation
very weak: < 0,15
weak: 0,15-0,25
moderate: 0,25-0,40
strong: 0,40-0,75
very strong: >0,75
"""
corr = stats.spearmanr(arrayA, arrayB)
coefficient = float(format(corr[0], '.3f'))
pvalue = float(corr[1])
print "pvalue: ", pvalue
## Make scatterplot if rho >= threshold or <= -theshold
if (coefficient >= threshold) or (coefficient <= -threshold):
# Make scatterplot
fig = plt.figure(figsize=(6,6))
ax1 = fig.add_subplot(1, 1, 1)
#plot = sns.jointplot(x=arrayA, y=arrayB, kind="hex", xlim=(0,40), gridsize=50, dropna=True, cmap="Blues", stat_func=spearmanr)
plot = sns.jointplot(x=arrayA, y=arrayB, kind="kde", space=0, xlim=(0,30), gridsize=50, dropna=True, cmap="Blues", stat_func=spearmanr)
plt.xlabel('# L1', fontsize=12)
plt.ylabel('Replication time', fontsize=12)
# sns.plt.subplots_adjust(left=0.2, right=0.8, top=0.8, bottom=0.2) # shrink fig so cbar is visible
# cax = plot.fig.add_axes([.85, .25, .05, .4]) # x, y, width, height
# sns.plt.colorbar(cax=cax)
#sns.jointplot(x=arrayA, y=arrayB, kind="kde", space=0, color="b", xlim=(0,30))
## Save figure
fileName = outPath + '_' + str(coefficient) + '_correlation.pdf'
plt.savefig(fileName)
return coefficient, pvalue
#### MAIN ####
## Import modules ##
评论列表
文章目录