案例如下:将以下frac数据绘制扇形图,并且设置其扇形标签为label
frac = [1/50,6/50,11/50,15/50,9/50,6/50,2/50]
label = [’[3,4]’,’(4,5]’,’(5,6]’,’(6,7]’,’(7,8]’,’(8,9]’,’(9,10]’]
代码:
fig = plt.figure(figsize=(8,6), dpi=80)
frac = [1/50,6/50,11/50,15/50,9/50,6/50,2/50]
labels = ['[3,4]','(4,5]','(5,6]','(6,7]','(7,8]','(8,9]','(9,10]']
explode = [0,0,0,0.1,0,0,0]
# 作图,设置标签,突出显示块,显示百分比
plt.pie(frac, labels=labels, explode=explode, autopct="%.1f%%")
plt.title("分布情况")
plt.show()