python数据可视化(二)——饼图

python 画图–饼图
python Matplotlib 系列教程(六)——绘制饼图
matplotlib.pyplot.pie

pie(x,参数)

例子
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf", size=14)  

beijing = [17,17,23,43]
shanghai = ['19%','4%','23%','54%']
guangzhou = ['53%','25%','13%','9%']
shenzhen = ['41%','22%','20%','17%']

label = ['2-3 years','3-4 years','4-5 years','5+ years']
color = ['red','green','yellow','purple']

indic = []

#我们将数据最大的突出显示
for value in beijing:
    if value == max(beijing):
        indic.append(0.1)
    else:
        indic.append(0)

plt.pie(
    beijing,
    labels=label,
    colors=color,
    startangle=90,
    shadow=True,
    explode=tuple(indic),#tuple方法用于将列表转化为元组
    autopct='%1.1f%%'#是数字1,不是l
)


plt.title(u'饼图示例——统计北京程序员工龄', FontProperties=font)

plt.show()

在这里插入图片描述

参数说明
  • x:每一块的比例,如果sum(x)大于 1 ,则会进行归一化

  • labels:设置圆圈外围标签

  • color:各比例的显示颜色

  • shadow:是否显示阴影

  • autopct:显示各比例数值

  • explode:分割,里面的数据的一个列表,0表示不分割,数值表示分割多少。

  • explode=[0,0.2,0,0.1,0]
    

在这里插入图片描述

  • radius:半径,默认为 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值