饼图

Pie(饼图)

饼图主要用于表现不同类目的数据在总和中的占比。每个的弧度表示数据数量的比例。

from pyecharts import Pie

attr = ["EM", "DM", "OBTM", "AFF", "SOC", "Others"]
v1 = [11234, 12534, 13454, 10454, 3054, 7034]
pie = Pie("某产品广告各渠道转化占比", width=1000)
pie.add("", attr, v1, is_label_show=True)
pie
<div id="c8117b807e444485bad1f84231bb1d2b" style="width:1000px;height:400px;"></div>

圆环图(doughnut)

中间内空,与饼图表达数据形式一样

radius -> list

  • 饼图的半径,数组的第一项是内半径,第二项是外半径,默认为 [0, 75],默认设置成百分比,相对于容器高宽中较小的一项的一半
from pyecharts import Pie

attr = ["EM", "DM", "OBTM", "AFF", "SOC", "Others"]
v1 = [11234, 12534, 13454, 10454, 3054, 7034]
pie = Pie("某产品广告各渠道转化", title_pos='center')
pie.add("", attr, v1,
        radius=[40, 75],  # 饼图的半径,数组的第一项是内半径,第二项是外半径,默认为 [0, 75]
                          # 默认设置成百分比,相对于容器高宽中较小的一项的一半
        is_label_show=True, label_text_color=None,
        legend_orient='vertical', legend_pos='left')
pie
<div id="b9aab43618314f7ba80ec42ed0d79823" style="width:800px;height:400px;"></div>

南丁格尔玫瑰图是弗罗伦斯·南丁格尔所发明的。又名极区图。是一种圆形的直方图。 南丁格尔自己常昵称这类图为鸡冠花图(coxcomb),并且用以表达军医院季节性的死亡率,对象是那些不太能理解传统统计报表的公务人员。

rosetype -> str
是否展示成南丁格尔图,通过半径区分数据大小,有’radius’和’area’两种模式。默认为’radius’

  • radius:扇区圆心角展现数据的百分比,半径展现数据的大小
  • area:所有扇区圆心角相同,仅通过半径展现数据大小
from pyecharts import Pie

attr = ['Desktop','Imaging','Notebook','SNP','Server','Service']
v1 = [2291,1163,1616,513,3695,580]
v2 = [3311,1489,3509,163,2659,833]

pie = Pie("饼图-玫瑰图示例", title_pos='center', width=1200)
pie.add("渠道A", attr, v1, center=[25, 50],  # 饼图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标,默认为 [50, 50]
                                             # 默认设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度
        is_random=True, radius=[30, 75],
        rosetype='radius', 
        is_label_show=True)
pie.add("渠道B", attr, v2, center=[70, 50], is_random=True, radius=[30, 75],
        rosetype='area',
        is_legend_show=False, is_label_show=True)
pie
<div id="60a3e140a02540c19af71cf0847ece89" style="width:1200px;height:400px;"></div>

嵌套环形图

import random
from pyecharts import Pie

attr1 = ['直达', '营销广告', '搜索引擎']
attr2 = ['直达', '邮件', '联盟广告', '视频广告', '百度', '搜狗', '360','其他']
pie = Pie("嵌套环形图", width=1000, height=600)
pie.add("", attr1, [20,30,50], radius=[50, 55], center=[25, 50], is_random=True)
pie.add("", attr2, [20,10,15,5,20,10,10,10], radius=[10, 45], center=[25, 50], rosetype='radius')  # 只能用radius

pie.add("", attr1, [20,30,50], radius=[50, 55], center=[65, 50], is_random=True)
pie.add("", attr2, [20,10,15,5,20,10,10,10], radius=[0, 45], center=[65, 50], rosetype='area') 
pie
<div id="0d6fbbb645bd496283ff3bf51fb12324" style="width:1000px;height:600px;"></div>
import random
from pyecharts import Pie

attr1 = ['直达', '营销广告', '搜索引擎']
attr2 = ['直达', '邮件', '联盟广告', '视频广告', '百度', '搜狗', '360','其他']
pie = Pie("嵌套环形图", width=1000, height=600)
pie.add("", attr1, [20,30,50], radius=[50, 70], is_label_show=True, label_pos='inside')
pie.add("", attr2, [20,10,15,5,20,10,10,10], radius=[20, 45], is_label_show=True, label_pos='inside')
pie
<div id="7ed409f9d92a4aaab239470a57649adf" style="width:1000px;height:600px;"></div>

Sunburst(旭日图)

展示父子层级的不同类别数据的占比。

import random
from pyecharts import Pie

attr0 = ['流量来源']
attr1 = ['直达', '营销广告', '搜索引擎']
attr2 = ['直达', '邮件', '联盟广告', '视频广告', '百度', '搜狗', '360','其他']
pie = Pie("Sunburst(旭日图)", width=1000, height=600)
pie.add("", attr0, [100], radius=[0, 20], is_label_show=True, label_pos='inside')
pie.add("", attr1, [20,30,50], radius=[20, 40], is_label_show=True, label_pos='inside')
pie.add("", attr2, [20,10,15,5,20,10,10,10], radius=[40, 70], is_label_show=True, label_pos='inside',
        legend_orient='vertical',
        legend_pos='10',
        legend_top='30')
pie
<div id="c594c8fdea1f4ec0beede3138e1ddcf9" style="width:1000px;height:600px;"></div>
from pyecharts import Pie, Style

pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center', width=1000)

style = Style()
pie_style = style.add(
    label_pos="center",
    is_label_show=True,
    label_text_color=None,
    is_legend_show=False
)

pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], **pie_style)
pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], **pie_style)
pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], **pie_style)
pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], **pie_style)
pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], **pie_style)
pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], **pie_style)
pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], **pie_style)
pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], **pie_style)
pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], **pie_style)
pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24], 
#         is_legend_show=False,
#         legend_top="center",
        **pie_style)

pie
<div id="39c06b5add484272b6ffc907cbd64ad1" style="width:1000px;height:400px;"></div>

饼图 vs. 柱状图

from pyecharts import Pie, Bar, Page

# step 1
page = Page()

# data
data = [('人物传记', 1234), ('伦理', 1254), ('冒险', 1345), ('剧情', 17454), ('动作', 3054),
        ('喜剧', 7034), ('奇幻', 1234), ('悬疑', 1354), ('惊悚', 10454), ('战争', 4054), ('政治', 34),
        ('文艺', 13234), ('歌舞', 1534), ('武侠', 13454), ('爱情', 12454), ('犯罪', 6054), ('科幻', 7034), 
        ('黑色', 534)]

attr, value = Bar.cast(sorted(data, key=lambda x: x[1], reverse=True))

# pie
pie = Pie("不同类型电影数量", "--饼图", width=1000)
pie.add("", attr, value, radius=[40, 75], label_text_color=None,
        is_label_show=True,
#         legend_orient='vertical',
        is_legend_show=False,
#         legend_pos='15%'
       )

# step 2
page.add(pie)

# bar
bar = Bar("不同类型电影数量", "--柱状图", width=1000)
bar.add("", attr, value,
        is_label_show=True,
        is_legend_show=True,
        legend_pos='top',
        xaxis_rotate=30)

# step 3
page.add(bar)

page
<div id="11fd2f9bf050456d98024394dc3f9fa9" style="width:1000px;height:400px;"></div>
<div id="d1211723826140079f152c53cb77d4e9" style="width:1000px;height:400px;"></div>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值