手把手教你用Pyecharts绘制这3种超经典图表

大数据DT

共 3310字,需浏览 7分钟

 · 2022-02-17

导读:Pyecharts绘制上下组合图、左右组合图、一轴多图,超经典!


作者:黄伟呢

来源:数据分析与统计学之美(ID:huang_superme)



01 上下组合


from pyecharts.charts import Bar, Line, Grid
from pyecharts import options

# 1、准备数据
country = ['巴西''俄罗斯''印度''英国''西班牙''伊朗''德国''土耳其''法国']
quezheng = [923189,553301,354065,298136,244328,192439,188252,181298,157716]
siwang = [45241,7478,11903,41969,27136,9065,8802,4842,29547]

# 2、绘制柱形图
bar = (
    Bar()
    .add_xaxis(country)
    .add_yaxis("确诊人数", quezheng)
    .add_yaxis("死亡人数", siwang)
    .set_global_opts(title_opts=options.TitleOpts(title="我是标题", subtitle="我是副标题"))
)

# 3、绘制线图
line = (
    Line()
    .add_xaxis(country)
    .add_yaxis("quzheng人数", quezheng)
    .add_yaxis("siwang人数", siwang)
    .set_global_opts(legend_opts=opts.LegendOpts(pos_bottom="45%"))
)

# 4、创建组合图
(Grid(init_opts=opts.InitOpts(width='750px', height='350px'))
 .add(bar,grid_opts=opts.GridOpts(pos_bottom="60%"))
 .add(line,grid_opts=opts.GridOpts(pos_top="60%"))
).render_notebook()


结果如下:




02 左右组合


from pyecharts.charts import Bar, Line, Grid
from pyecharts import options

# 1、准备数据
country = ['巴西''俄罗斯''印度''英国''西班牙''伊朗''德国''土耳其''法国']
quezheng = [923189,553301,354065,298136,244328,192439,188252,181298,157716]
siwang = [45241,7478,11903,41969,27136,9065,8802,4842,29547]

# 2、绘制柱形图
bar = (
    Bar()
    .add_xaxis(country)
    .add_yaxis("确诊人数", quezheng, label_opts=opts.LabelOpts(is_show=False))
    .add_yaxis("死亡人数", siwang, label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(title_opts=options.TitleOpts(title="我是标题", subtitle="我是副标题"),
                     legend_opts=opts.LegendOpts(pos_right="20%"))
)

# 3、绘制线图
line = (
    Line()
    .add_xaxis(country)
    .add_yaxis("quzheng人数", quezheng, label_opts=opts.LabelOpts(is_show=False))
    .add_yaxis("siwang人数", siwang, label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(legend_opts=opts.LegendOpts(pos_left="20%"))
)

# 4、创建组合图
(Grid(init_opts=opts.InitOpts(width='750px', height='350px'))
 .add(bar,grid_opts=opts.GridOpts(pos_left="55%"))
 .add(line,grid_opts=opts.GridOpts(pos_right="55%"))
).render_notebook()


结果如下:




03 一轴多图


from pyecharts.charts import Bar, Line, Grid
from pyecharts import options

# 1、准备数据
from pyecharts.charts import Bar, Line, Grid
from pyecharts import options

# 1、准备数据
country = ['巴西''俄罗斯''印度''英国''西班牙''伊朗''德国''土耳其''法国']
quezheng = [923189,553301,354065,298136,244328,192439,188252,181298,157716]
siwang = [45241,7478,11903,41969,27136,9065,8802,4842,29547]

# 2、绘制柱形图
bar = (
    Bar(init_opts=opts.InitOpts(width='750px', height='350px'))
    .add_xaxis(country)
    .add_yaxis("确诊人数", quezheng)
    .add_yaxis("死亡人数", siwang)
    .set_global_opts(title_opts=options.TitleOpts(title="我是标题", subtitle="我是副标题"))
)

# 3、绘制线图
line = (
    Line()
    .add_xaxis(country)
    .add_yaxis("确诊人数", quezheng, label_opts=opts.LabelOpts(is_show=False))
    .add_yaxis("死亡人数", siwang, label_opts=opts.LabelOpts(is_show=False))
)

# 4、创建组合图
bar.overlap(line).render_notebook()


结果如下:




延伸阅读👇

延伸阅读《ECharts数据可视化》


干货直达👇



更多精彩👇

在公众号对话框输入以下关键词
查看更多优质内容!

读书 | 书单 | 干货 | 讲明白 | 神操作 | 手把手
大数据 | 云计算 | 数据库 | Python | 爬虫 | 可视化
AI | 人工智能 | 机器学习 | 深度学习 | NLP
5G | 中台 | 用户画像 数学 | 算法 数字孪生

据统计,99%的大咖都关注了这个公众号
👇
浏览 5
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报