【2.4】散点图线性拟合(matplotlib-linear)

案例:

from scipy import stats
import matplotlib.pyplot as plt


x = [1,2,3,4]
y = [3,5,7,10]   # 10, not 9, so the fit isn't perfect

slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
line = [slope*ii for ii in x] + intercept

plt.plot(x, y, 'o', x, line)
plt.annotate('R=%.2f\n' % (r_value), xy=(0.05, 0.9), xycoords='axes fraction',color='red')

plt.xlim(0, 5)
plt.ylim(0, 12)
plt.show()

参考资料

个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn

Sam avatar
About Sam
专注生物信息 专注转化医学