1 import  pandas
 2 from matplotlib  import  pyplot
 3 from  scipy.stats  import  linregress
 4 sale=pandas.read_excel('销售.xlsx',dtype={'date':str})
 5 
 6 
 7 slope,intercept,r,p,std_err=linregress(sale.index,sale.revenue)
 8 
 9 exp=sale.index*slope+intercept       
10 
11 pyplot.scatter(sale.index,sale.revenue)   #绘制散点图
12 
13 pyplot.plot(sale.index,exp,color='red')   #绘制直线图
14 
15 pyplot.title(f"y={slope}*x+{intercept}")   #得出线性回归方差
16 
17 pyplot.xticks(sale.index,sale.date,rotation=45)  #sale.index确定刻度大小,sale.date确定刻度上的数据
18 
19 pyplot.tight_layout()
20 pyplot.show()

 

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/luckiness/p/13124165.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!