gpt4 book ai didi

python - 如何在 python matplotlib 点(散点图)图中添加趋势线?

转载 作者:IT老高 更新时间:2023-10-28 21:33:30 26 4
gpt4 key购买 nike

如何将趋势线添加到使用 matplotlib.scatter 绘制的点图中?

最佳答案

如解释 here

在 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])

关于python - 如何在 python matplotlib 点(散点图)图中添加趋势线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26447191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com