# 饼图:pie(x, explode=None, labels=None, colors=None, autopct=None,pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None,radius=None, counterclock=True, wedgeprops=None, textprops=None,center=(0, 0), frame=False, rotatelabels=False, hold=None, data=None)
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
# plt.figure(figsize=(6, 6)) # 图片画布设置
values = [2, 5, 12, 70, 2, 9]
explode = [0, 0, 0, 0.1, 0, 0] # 饼图间隔,数目与values值对应,所有间隔值可以有差异
labels = ['娱乐', '育儿', '饮食', '房贷', '交通', '其它'] # 标签
# colors = ['red', 'blue', 'green'] # 颜色
# plt.axis('equal') # 饼图长宽相等
plt.pie(values, explode=explode, labels=labels, startangle=150,
autopct='%1.2f%%', radius=1, shadow=True) # autopct控制饼图内百分比设置
plt.title('8月份家庭支出') # 设置标题
# plt.savefig('./饼图') # 在当前目录下保存图片
plt.legend(loc="upper right", fontsize=10,
bbox_to_anchor=(1.1, 1.05), borderaxespad=0.3)
# bbox_to_anchor=[0.5, 0.5] # 外边距 上边 右边
# borderaxespad = 0.3图例的内边距
# plt.savefig('./8月份家庭支出.png')#保存
plt.show()