利用python的matplotlib画出基本饼状图

本文介绍了如何使用Python的matplotlib库绘制基础的饼状图。通过示例代码和运行结果图,展示了饼状图的创建过程。
摘要由CSDN通过智能技术生成

以下是代码

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
#用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号

plt.figure(figsize=(6,9))
#定义饼状图的标签,标签是列表
labels = [u'第一部分',u'第二部分',u'第三部分']
sizes = [60,30,10]
colors = ['red','yellowgreen','lightskyblue']
explode = (0.05,0,0)
patches,l_text,p_text = plt.pie(sizes,explode=explode,labels=labels,colors=colors,
                                labeldistance = 1.1,autopct = '%3.1f%%',
                                shadow =False,startangle = 90,pctdistance = 0.6)

for t in l_text:
    t.set_size(30)
for t in p_text:
    t.set_size(20)
plt.axis('equal')
plt.legend()
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值