目录
下表列出了饼状图的各项参数:
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是每个数据对应的标签。
显示结果如下: