利用python實現(xiàn)周期財務(wù)統(tǒng)計可視化
正文之前
上午給爸爸打了個電話慶祝他50歲生日,在此之前搞了個大掃除,看了會知乎,到實驗室已經(jīng)十一點多了。約喜歡的妹子吃飯失敗,以至于工作積極性收到了打擊,所以就寫個程序來統(tǒng)計下開學(xué)十一天的財務(wù)消費情況,更清楚的認(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"時間")
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)) #調(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è)置
pctdistance = 0.6) #數(shù)值距圓心半徑倍數(shù)距離
#patches餅圖的返回值,texts1餅圖外label的文本,texts2餅圖內(nèi)部的文本
# x,y軸刻度設(shè)置一致,保證餅圖為圓形
plt.axis('equal')
plt.show()
print("十天合計消費:%d"%(fruit_all+other_all+food_all))
其實就畫了倆圖,一個是折線圖,一個餅圖


最后總結(jié)出來的就是這樣了。。

至于每天怎么做統(tǒng)計的,也放個樣子出來。

每天花個幾分鐘統(tǒng)計下,然后隔段時間來做個統(tǒng)計,更清晰的知道自己最近花了多少錢,錢都去哪兒了。很有利于我脫離月光族的狀態(tài)。。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。
相關(guān)文章
對python中數(shù)據(jù)集劃分函數(shù)StratifiedShuffleSplit的使用詳解
今天小編就為大家分享一篇對python中數(shù)據(jù)集劃分函數(shù)StratifiedShuffleSplit的使用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12
Python日志打印里logging.getLogger源碼分析詳解
在本篇文章里小編給大家整理的是一篇關(guān)于Python logging.getLogger源碼分析的相關(guān)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。2021-01-01
Python調(diào)用Google?Bard的圖文詳解
Google?Bard?是一種開源數(shù)據(jù)可視化和探索工具,可為?開發(fā)人員?提供支持,本文主要為大家介紹了Python調(diào)用Google?Bard的方法,需要的可以參考下2023-08-08
Python 列表(List)的底層實現(xiàn)原理分析
這篇文章主要介紹了Python 列表(List)的底層實現(xiàn)原理分析,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03

