How to add trendline in python matplotlib dot (sca

2019-01-08 20:12发布

How could I add trendline to a dot graph drawn using matplotlib.scatter?

1条回答
Luminary・发光体
2楼-- · 2019-01-08 21:13

as explained here

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])
查看更多
登录 后发表回答