正文之前
上午給爸爸打了個(gè)電話慶祝他50歲生日,在此之前搞了個(gè)大掃除,看了會知乎,到實(shí)驗(yàn)室已經(jīng)十一點(diǎn)多了。約喜歡的妹子吃飯失敗,以至于工作積極性收到了打擊,所以就寫個(gè)程序來統(tǒng)計(jì)下開學(xué)十一天的財(cái)務(wù)消費(fèi)情況,更清楚的認(rèn)識自己。
正文
廢話不多說,先放代碼:
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"時(shí)間")
plt.ylabel(u"消費(fèi)")
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)) #調(diào)節(jié)圖形大小
labels = [u'Food '+str(int(food_all)),u'Fruit '+str(fruit_all),u'Other '+str(other_all)] #定義標(biāo)簽
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%%', #數(shù)值保留固定小數(shù)位
shadow = False, #無陰影設(shè)置
startangle =90, #逆時(shí)針起始角度設(shè)置
pctdistance = 0.6) #數(shù)值距圓心半徑倍數(shù)距離
#patches餅圖的返回值,texts1餅圖外label的文本,texts2餅圖內(nèi)部的文本
# x,y軸刻度設(shè)置一致,保證餅圖為圓形
plt.axis('equal')
plt.show()
print("十天合計(jì)消費(fèi):%d"%(fruit_all+other_all+food_all))
其實(shí)就畫了倆圖,一個(gè)是折線圖,一個(gè)餅圖
最后總結(jié)出來的就是這樣了。。
至于每天怎么做統(tǒng)計(jì)的,也放個(gè)樣子出來。
每天花個(gè)幾分鐘統(tǒng)計(jì)下,然后隔段時(shí)間來做個(gè)統(tǒng)計(jì),更清晰的知道自己最近花了多少錢,錢都去哪兒了。很有利于我脫離月光族的狀態(tài)。。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對腳本之家的支持。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

