import matplotlib.pyplot as plt
x = [4, 9, 21, 55, 30, 18]
labels = ['math', 'history', 'chemistry', 'physics', 'biology','Enrlish']
explode = [0, 0.01, 0.01, 0.02, 0.03, 0]
plt.pie(x, labels=labels, explode=explode,shadow=True,autopct='%1.1f%%',startangle=60,radius=1)
plt.show()
#图画的比较丑,不过可以通过下面的设置在plt.pie中慢慢调节!

 使用matplotlib画饼图 Hadoop


#其它设置如下所示
# 每一块)的比例,如果sum(x) > 1会使用sum(x)归一化
# labels (每一块)饼图外侧显示的说明文字
# explode (每一块)离开中心距离
# startangle 起始绘制角度,默认图是从x轴正方向逆时针画起,如设定=90则从y轴正方向画起
# shadow 是否阴影
# labeldistance label绘制位置,相对于半径的比例, 如<1则绘制在饼图内侧
# autopct 控制饼图内百分比设置,可以使用format字符串或者format function
# '%1.1f'指小数点前后位数(没有用空格补齐)
# pctdistance 类似于labeldistance,指定autopct的位置刻度
# radius 控制饼图半径
# 返回值:
# 如果没有设置autopct,返回(patches, texts)
# 如果设置autopct,返回(patches, texts, autotexts
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。