开发者

Pyecharts 绘制3种常用的图形

开发者 https://www.devze.com 2022-12-11 13:17 出处:网络 作者: Python数据挖掘
目录1.上下组合2.左右组合3.一轴多图大家好,今天给大家利用 Pyecharts 绘制上下组合图、左右组合图、一轴多图,好用超经典,分析给大家
目录
  • 1.上下组合
  • 2.左右组合
  • 3.一轴多图

大家好,今天给大家利用 Pyecharts 绘制上下组合图、左右组合图、一轴多图,好用超经典,分析给大家

1.上下组合

from pyecharts.ch编程客栈arts 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()

结果如下:

Pyecharts 绘制3种常用的图形

2.左右组合

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.LegendOWYsQSpts(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()

结果如下:

Pyecharts 绘制3种常用的图形

3.一轴多图

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

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

# 1、准备数据
country = ['巴西http://www.cppcns.com', '俄罗斯', '印度', '英国', '西班牙', '伊朗', '德国', '土耳其', '法国']
quezheng = [923189,553301,354065,298136,244328,192439,188252,181298,157716]
siwang = [45241,7478,11903,41969,27136,9065,8802,484www.cppcns.com2,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()

结果如下:

Pyecharts 绘制3种常用的图形

到此这篇关于Pyecharts 绘制3种常用的图形的文章就介绍到这了,更多相关Pyecharts 绘制常用的图形内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号