当前位置:   article > 正文

五类24例pyecharts图表分享(附代码)_pyecharts代码

pyecharts代码

01 Pie Chart

基础饼图

在这里插入图片描述

from pyecharts import options as opts
from pyecharts.charts import *
from pyecharts.globals import *


x_data = ["直接访问", "邮件营销", "联盟广告", "视频广告", "搜索引擎"]
y_data = [335, 310, 274, 235, 700]
data_pair = [list(z) for z in zip(x_data, y_data)]
data_pair.sort(key=lambda x: x[1])

p = (
    Pie(init_opts=opts.InitOpts(theme=ThemeType.WALDEN,
                                page_title="Pie- Base"))
    .add(
        series_name="访问来源",
        data_pair=data_pair,
        radius="50%",
        center=["50%", "50%"],
        # is_clockwise=True,  # 扇区排布方向
        label_opts=opts.LabelOpts(is_show=True, position="center"),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="Customized Pie",
            pos_left="center",
            pos_top="20",
        ),
        legend_opts=opts.LegendOpts(is_show=False)
    )
    .set_series_opts(
        tooltip_opts=opts.TooltipOpts(
            trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"
        ),
        label_opts=opts.LabelOpts(color="rgba(0, 0, 0, 0.5"),
    )
    .render("Pie01.html")
)
os.system("Pie01.html")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

玫瑰图

在这里插入图片描述

from pyecharts import options as opts
from pyecharts.charts import *
from pyecharts.globals import *


x_data = ["直接访问", "邮件营销", "联盟广告", "视频广告", "搜索引擎"]
y_data = [335, 310, 274, 235, 700]
data_pair = [list(z) for z in zip(x_data, y_data)]
data_pair.sort(key=lambda x: x[1])

p = (
    Pie(init_opts=opts.InitOpts(theme=ThemeType.INFOGRAPHIC,
                                page_title="Pie- RoseType"))
    .add(
        series_name="访问来源",
        data_pair=data_pair,
        radius="50%",  # 饼图
        center=["50%", "50%"],

        # 是否展示成南丁格尔图,通过半径区分数据大小
        rosetype="radius",  # 通过半径区分数据大小
        # rosetype="area",  # 通过面积区分数据大小

        is_clockwise=True,  # 扇区排布方向
        label_opts=opts.LabelOpts(is_show=True, position="center"),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="Pie - Rosetype",
            pos_left="center",
            pos_top="20",
        ),
        legend_opts=opts.LegendOpts(is_show=False)
    )
    .set_series_opts(
        tooltip_opts=opts.TooltipOpts(
            trigger="item", formatter="<b>{a}</b> <br/>{b}: {c} ({d}%)"
        ),
        label_opts=opts.LabelOpts(color="rgba(0, 0, 0, 0.5"),
    )
    .render("Pie02.html")
)
os.system("Pie02.html")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

普通圆环图

在这里插入图片描述

from pyecharts import options as opts
from pyecharts.charts import *
from pyecharts.globals import *

x_data = ["直接访问", "邮件营销", "联盟广告", "视频广告", "搜索引擎"]
y_data = [335, 310, 274, 235, 700]
data_pair = [list(z) for z in zip(x_data, y_data)]
data_pair.sort(key=lambda x: x[1])

p = (
    Pie(init_opts=opts.InitOpts(theme=ThemeType.WALDEN,
                                page_title="Pie- Ring"))
    .add(
        series_name="访问来源",
        data_pair=data_pair,
        radius=["35%", "75%"],  # 圆环图
        center=["50%", "50%"],
        is_clockwise=True,  # 扇区排布方向
        label_opts=opts.LabelOpts(is_show=True, position="center"),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="Pie - Ring",
            pos_left="center",
            pos_top="20",
        ),
        legend_opts=opts.LegendOpts(is_show=False)
    )
    .set_series_opts(
        tooltip_opts=opts.TooltipOpts(
            trigger="item", formatter="<b>{a}</b> <br/>{b}: {c} ({d}%)"
        ),
        label_opts=opts.LabelOpts(color="rgba(0, 0, 0, 0.5",
                                  formatter="{b}: {c} ({d}%)",
                                  font_size=14,
                                  font_weight="bold",
                                  font_family="Courier New",
                                  ),
    )
    .render("Pie03.html")
)
os.system("Pie03.html")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

富文本饼图

在这里插入图片描述

from pyecharts import options as opts
from pyecharts.charts import *
from pyecharts.globals import *

inner_x_data = ["直达", "营销广告", "搜索引擎"]
inner_y_data = [335, 679, 1548]

outer_x_data = ["直达", "营销广告", "搜索引擎", "邮件营销", "联盟广告", "视频广告", "百度", "谷歌", "必应", "其他"]
outer_y_data = [335, 310, 234, 135, 1048, 251, 147, 102]

p = (
    Pie(init_opts=opts.InitOpts(theme=ThemeType.WALDEN,
                                page_title="Nested Pie with Rich Text"))
    .add(
        series_name="访问来源",
        data_pair=[list(z) for z in zip(inner_x_data, inner_y_data)],
        radius=[0, "30%"],
        label_opts=opts.LabelOpts(position="inner"),
    )
    .add(
        series_name="访问来源2",
        data_pair=[list(z) for z in zip(outer_x_data, outer_y_data)],
        radius=["40%", "60%"],
        label_opts=opts.LabelOpts(
            position="outside",
            formatter="{a|{a}}{abg|}\n{hr|}\n {b|{b}} : {c} {per|{d}%}  ",
            background_color="#eee",
            border_color="#aaa",
            border_width=1,
            border_radius=4,
            rich={
   
                "a": {
   "color": "#999", "lineHeight": 22, "align": "center"},
                "abg": {
   
                    "backgroundColor": "#e3e3e3",
                    "width": "100%",
                    "align": "right",
                    "height": 22,
                    "borderRadius": [4, 4, 0, 0],
                },
                "hr": {
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/71037
推荐阅读
相关标签
  

闽ICP备14008679号