73

matplotlib.scatter を使用して描画されたドット グラフにトレンドラインを追加するにはどうすればよいですか?

4

1 に答える 1

101

ここで説明したように

numpy の助けを借りて、たとえば線形フィッティングを計算できます。

# 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])
于 2014-10-19T05:06:37.663 に答える