18  饼图

18.1 医护构成比

# 扇形图例标识
import matplotlib.pyplot as plt

# 这两行代码解决 plt 中文显示的问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# 扇形图例标识
labels = ['医生', '护士']

# 扇形大小
sizes = [33, 149]
# 第二块扇形偏移
explode = [0, 0.05]

# 创建图形
fig, ax = plt.subplots()

# 开始画饼图
ax.pie(sizes, labels=labels, explode=explode, autopct='%1.1f%%')

# 确保画的饼是圆的
ax.axis('equal');

# 标题
ax.set_title('医护人员构成比');

# 设置图例
# ax.legend(labels=labels);
# fig.savefig('ratio1.jpg',dpi=300)

18.2 医生职称构成比

# 扇形图例标识
labels = ['高级', '中级', '初级']

# 扇形大小
sizes = [10, 11, 12]
# 第二块扇形偏移
explode = [0, 0.02, 0.02]

# 创建图形
fig, ax = plt.subplots()

# 开始画饼图
ax.pie(sizes, labels=labels, explode=explode, autopct='%1.1f%%')

# 确保画的饼是圆的
ax.axis('equal');

# 标题
ax.set_title('医生职称构成比');

# 设置图例
# ax.legend(labels=labels);
# fig.savefig('ratio2.jpg',dpi=300)