2017-05-12 63 views
1

如果我想將它作爲我的情節中的註釋,如何將spearmanr結果舍入爲小數點後3位?將spearmanr結果舍入爲小數點後3位

import matplotlib.pyplot as plt 
import scipy.stats 
import numpy as np 

percent = np.array([34.72,47.22,40.97,43.06,57.64,50.00,69.44]) 
year = np.array([2009,2010,2011,2012,2013,2014,2015]) 

fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(year,percent, marker='o') 
ax.set_ylim(20,80) 
ax.set_xticks(year) 

ax.annotate(scipy.stats.spearmanr(year,percent), xy=(2009,70)) 

plt.show() 

Output 我想要的註解留在圖表上。

回答

1

重新設置註釋中的文本的格式。與此更換第二到最後一行:

r = scipy.stats.spearmanr(year, percent) 
text = "correlation: {:.3f}, pvalue:{:.3f}".format(r.correlation, r.pvalue) 
ax.annotate(text, xy=(2009,70)) 

輸出

enter image description here

相關問題