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.uj5u.com/houduan/131508.html
標籤:Python
上一篇:13.Django-分頁
下一篇:十大排序演算法(筆記)
