正文之前
上午給爸爸打了個電話慶祝他50歲生日,在此之前搞了個大掃除,看了會知乎,到實驗室已經十一點多了。約喜歡的妹子吃飯失敗,以至于工作積極性收到了打擊,所以就寫個程序來統計下開學十一天的財務消費情況,更清楚的認識自己。
正文
廢話不多說,先放代碼:
import matplotlib.pyplot as plt import matplotlib from pylab import mpl plt.rcParams['font.sans-serif']=['SimHei'] def getAll(x): s=0 for i in x: s+=i return s sump = [374.9,70,85.5,72.9,33.7,14.8,35.4,30.1,66.52,114.3,-13] fruit = [0,0,0,10,0,0,0,0,35,0,0] other = [338.6,50,53.8,49.5,10,0,0,0,6.42,92,-34] food = [] for i in range(len(sump)): food.append(sump[i] - fruit[i] - other[i]) date = [] for i in range(11): date.append("8."+str(i+14)) plt.xlabel(u"時間") plt.ylabel(u"消費") plt.plot(date,sump) plt.plot(date,fruit) plt.plot(date,other) plt.plot(date,food) plt.legend() plt.show() sump_all = getAll(sump) fruit_all = getAll(fruit) other_all = getAll(other) food_all = getAll(food) plt.figure(figsize=(6,9)) #調節圖形大小 labels = [u'Food '+str(int(food_all)),u'Fruit '+str(fruit_all),u'Other '+str(other_all)] #定義標簽 sizes = [food_all,fruit_all,other_all] #每塊值 colors = ['red','yellowgreen','lightskyblue'] #每塊顏色定義 explode = (0,0,0) #將某一塊分割出來,值越大分割出的間隙越大 patches,text1,text2 = plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct = '%3.2f%%', #數值保留固定小數位 shadow = False, #無陰影設置 startangle =90, #逆時針起始角度設置 pctdistance = 0.6) #數值距圓心半徑倍數距離 #patches餅圖的返回值,texts1餅圖外label的文本,texts2餅圖內部的文本 # x,y軸刻度設置一致,保證餅圖為圓形 plt.axis('equal') plt.show() print("十天合計消費:%d"%(fruit_all+other_all+food_all))
其實就畫了倆圖,一個是折線圖,一個餅圖
最后總結出來的就是這樣了。。
至于每天怎么做統計的,也放個樣子出來。
每天花個幾分鐘統計下,然后隔段時間來做個統計,更清晰的知道自己最近花了多少錢,錢都去哪兒了。很有利于我脫離月光族的狀態。。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
