1、功能介绍:
使用 python 的 matplotlib 库来创建一个简单的饼图。
2、代码部分:
import matplotlib.pyplot as plt# 示例数据
labels = ['A', 'B', 'C', 'D', 'E'] # 类别标签
sizes = [15, 30, 45, 5, 5] # 每个类别对应的数值(百分比)# 绘制饼图
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, colors=['#ff9999','#66b3ff','#99ff99','#ffcc99','#c2c2f0'])# 添加标题
plt.title('Pie Chart Example')# 显示图形
plt.show()