第5天-python饼图绘制
一、基础饼图绘制(Matplotlib)
1. 环境准备
python
复制
下载
pip install matplotlib numpy
2. 基础饼图代码
python
复制
下载
import matplotlib.pyplot as plt# 数据准备 labels = ['1', '2', '3', '4'] sizes = [30, 25, 15, 30] # 各部分占比(总和建议100) colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99'] # 自定义颜色plt.figure(figsize=(8, 6)) # 设置画布大小# 绘制饼图 plt.pie(sizes, labels=labels, colors=colors,autopct='%1.1f%%', # 显示百分比格式startangle=90