matplotlib 绘制并列饼状图

3 篇文章 0 订阅
1 篇文章 0 订阅

废话不说,先上图。这个是实际效果。在这里插入图片描述

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
# 同时绘制2个饼图
labels = [u'损伤/中毒', u'呼吸系统疾病', u'肿瘤', u'心血管病', u'其他']
sizes = [7.79, 11.57, 23.07, 45.91, 11.66]
sizes1 = [5.90, 10.92, 26.11, 43.56, 13.51]
colors = ['orange','blueviolet','dodgerblue','red','green']

# 创建四个饼图型
fig, axs = plt.subplots(1, 2)

# 第一个饼图设置
patches, l_text, p_text = axs[0].pie(sizes, labels=labels, colors=colors,
                                   labeldistance=1.1, autopct='%2.2f%%', shadow=False,
                                   startangle=140, pctdistance=0.6)

# 第二个饼图设置,设置第二个扇形偏移
patches, l_text, p_text = axs[1].pie(sizes1, labels=labels, labeldistance=1.1, autopct='%2.2f%%', shadow=False,
                                   startangle=140, pctdistance=0.6)

for t in l_text:
    t.set_size = 30
for t in p_text:
    t.set_size = 20
# 设置x,y轴刻度一致,这样饼图才能是圆的
plt.axis('equal')
plt.legend(loc='upper center', bbox_to_anchor=(-0.15, 1.1))

plt.grid()
plt.show()
fig, axs = plt.subplots(1, 2)
axs[0].pie()
axs[1].pie()
#这个是确定画几个,以及每个图具体内容的代码段

plt.subplots(1, 2)中1,2代表1行2列

plt.subplots(2, 2)
axs[0,0].pie()
axs[0,1].pie()
axs[1,0].pie()
axs[1,1].pie()
#该代码可以画2*2总共四个饼状图
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值