import matplotlib.pyplot as plt
sizes = [1,2,3,4,5]
labels = 'a','b','c','d','e'
explode = (0,0,0,0.1,0)
plt.pie(sizes,labels = labels,radius = 1.2,explode = explode,autopct = '%.1f%%',shadow = True,startangle = 90)
#radius半径/explode距离/autopct显示占比/shadow默认False为无阴影
plt.legend(ncol = 5)
plt.axis('equal')#圆形饼图
不设置nocl,nocl为列数
import matplotlib.pyplot as plt
sizes = [1,2,3,4,5]
labels = 'a','b','c','d','e'
explode = (0,0,0,0.1,0)
plt.pie(sizes,labels = labels,radius = 1.2,explode = explode,autopct = '%.1f%%',shadow = True,startangle = 90)
#radius半径/explode距离/autopct显示占比/shadow默认False为无阴影
plt.legend()
plt.axis('equal')#圆形饼图
环形图绘制
方式2:wedgeprops参数
labels = ['A','B','C','D','other']
share = [0.45,0.25,0.15,0.05,0.1]
share2 = [0.35,0.15,0.3,0.15,0.05]
colors = ['r','g','b','pink','y']
#explode = (0,0.1,0,0,0)
plt.pie(share,labels = labels,colors = colors,wedgeprops = dict(width = 0.6),autopct = '%.1f%%',pctdistance = 0.8)
#pcedistance:百分比文本到中心的距离
plt.pie(share2,labels = labels,radius = 0.7,colors = colors,wedgeprops = dict(width = 0.6,edgecolor = 'black'))