How to add trendline in python matplotlib dot (scatter) graphs?

前端 未结 1 1197
深忆病人
深忆病人 2020-11-29 23:58

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

相关标签:
1条回答
  • 2020-11-30 00:00

    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])
    
    0 讨论(0)
提交回复
热议问题