import matplotlib.pyplot as plt import numpy as np import matplotlib import sys
1.主体函数
#饼图 def die(labels,sizes,s=0): figure() #突出最大部分 explode =np.zeros(len(sizes)) explode[np.argmax(sizes)]=0.1 explode=tuple(explode) plt.pie(sizes,explode=explode,labels=labels,autopct='%1.1f%%',shadow=False,startangle=90) if s==1: Save() plt.show()
2. 相关函数
#获取当前文件夹,并根据文件名生成文件路径 def path(fileName): p=sys.path[0]+'\'+fileName return p #保存图片 def Save(): fig = plt.gcf() fig.set_size_inches(7.2, 4.2) fig.savefig(path('1.png'), dpi=400) #设置画布 def figure(): # 设置图形对象 :窗口 plt.figure('Figure Object 1', # 图形对象名称 窗口左上角显示 figsize = (8, 10), # 窗口大小 dpi = 120, # 分辨率 facecolor = 'white', # 背景色 )
3.实验
def data2(): x = ["lang","jiqing8","yujia","xiyou","jingang","shuaijiao"] y = [56.01,26.94,17.53,16.49,15.45,12.96] return x,y labels,sizes=data2() die(labels,sizes,s=1)
4.结果