如何在python matplotlib点(散点)图中添加趋势线? [英] How to add trendline in python matplotlib dot (scatter) graphs?
本文介绍了如何在python matplotlib点(散点)图中添加趋势线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何向使用matplotlib.scatter绘制的点图添加趋势线?
How could I add trendline to a dot graph drawn using matplotlib.scatter?
推荐答案
如此处
在numpy的帮助下,可以计算出线性拟合.
With help from numpy one can calculate for example a linear fitting.
# plot the data itself
pylab.plot(x,y,'o')
# calc the trendline
z = numpy.polyfit(x, y, 1)
p = numpy.poly1d(z)
pylab.plot(x,p(x),"r--")
# the line equation:
print "y=%.6fx+(%.6f)"%(z[0],z[1])
这篇关于如何在python matplotlib点(散点)图中添加趋势线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文