能來(lái)到這篇文章的對(duì) matplotlib 或者 seaborn 應(yīng)該都挺熟的??
所以直接上代碼和效果圖
import matplotlib.pyplot as plt
# make the pie circular by setting the aspect ratio to 1
# plt.figure(figsize=plt.figaspect(1))
values = [3, 12, 5, 8]
labels = ['a', 'b', 'c', 'd']
def make_autopct(values):
def my_autopct(pct):
total = sum(values)
val = int(round(pct*total/100.0))
# 同時(shí)顯示數(shù)值和占比的餅圖
return '{p:.2f}% ({v:d})'.format(p=pct,v=val)
return my_autopct
plt.pie(values, labels=labels, autopct=make_autopct(values))
plt.show()
更多商業(yè)數(shù)據(jù)分析案例等你來(lái)撩