8、饼图(ax.pie)

目录


下表列出了饼状图的各项参数:

ax.pie(x, explode=None, labels=None, colors=None, autopct=None, shadow=False, startangle=None, radius=None, textprops=None, ...)
x 数据序列
explode 扇形块远离圆心的举例
labels 数据对应标签
autopct 用于指定每个扇形块标注文本的样式,比如:定义百分数精度
colors 颜色
shadow 阴影
startangle 起始角度,逆时针
radius 饼图半径
textprops 图中文本属性

举例如下:

from matplotlib import pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.axis('equal')
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
ax.pie(students, labels = langs,autopct='%1.2f%%')
plt.show()

x是数据,labels是每个数据对应的标签。
显示结果如下:
饼图

猜你喜欢

转载自blog.csdn.net/weixin_45671036/article/details/112782487