python绘制桑基图

Ⅰ.原始数据

2022北京冬奥会奖牌榜

Ⅱ.程序

from pyecharts import options as opts
from pyecharts.charts import Sankey

nodes_list=[
    {'name':'Norway'},{'name':'Germany'},{'name':'China'},{'name':'United States'},{'name':'Sweden'},
    {'name':'Netherlands'},{'name':'Austria'},{'name':'Switzerland'},{'name':'Russia'},{'name':'France'},
    {'name':'Canada'},{'name':'Japan'},{'name':'Italy'},{'name':'South Korea'},{'name':'Slovenia'},
    {'name':'Finland'},{'name':'New Zealand'},{'name':'Australia'},{'name':'Britain'},{'name':'Hungary'},
    {'name':'Belgium'},{'name':'Czekh'},{'name':'Slovakia'},{'name':'Belorussia'},{'name':'Spain'},
    {'name':'Ukraine'},{'name':'Estonia'},{'name':'Latvia'},{'name':'Poland'},
    {'name':'Asia'},{'name':'North America'},{'name':'Oceania'},{'name':'Europe'}
]

links_list=[
    {'source': 'Asia', 'target': 'China', 'value': 15},
    {'source': 'Asia', 'target': 'Japan', 'value': 18},
    {'source': 'Asia', 'target': 'South Korea', 'value': 9},
    {'source': 'North America', 'target': 'United States', 'value': 25},
    {'source': 'North America', 'target': 'Canada', 'value': 26},
    {'source': 'Oceania', 'target': 'New Zealand', 'value': 3},
    {'source': 'Oceania', 'target': 'Australia', 'value': 4},
    {'source': 'Europe', 'target': 'Norway', 'value': 37},
    {'source': 'Europe', 'target': 'Germany', 'value': 27},
    {'source': 'Europe', 'target': 'Sweden', 'value': 18},
    {'source': 'Europe', 'target': 'Netherlands', 'value': 17},
    {'source': 'Europe', 'target': 'Austria', 'value': 18},
    {'source': 'Europe', 'target': 'Switzerland', 'value': 14},
    {'source': 'Europe', 'target': 'Russia', 'value': 32},
    {'source': 'Europe', 'target': 'France', 'value': 14},
    {'source': 'Europe', 'target': 'Italy', 'value': 17},
    {'source': 'Europe', 'target': 'Slovenia', 'value': 7},
    {'source': 'Europe', 'target': 'Finland', 'value': 8},
    {'source': 'Europe', 'target': 'Britain', 'value': 2},
    {'source': 'Europe', 'target': 'Hungary', 'value': 3},
    {'source': 'Europe', 'target': 'Belgium', 'value': 2},
    {'source': 'Europe', 'target': 'Czekh', 'value': 2},
    {'source': 'Europe', 'target': 'Slovakia', 'value': 2},
    {'source': 'Europe', 'target': 'Belorussia', 'value': 2},
    {'source': 'Europe', 'target': 'Spain', 'value': 1},
    {'source': 'Europe', 'target': 'Ukraine', 'value': 1},
    {'source': 'Europe', 'target': 'Estonia', 'value': 1},
    {'source': 'Europe', 'target': 'Latvia', 'value': 1},
    {'source': 'Europe', 'target': 'Poland', 'value': 1}
]

c=(
    Sankey()
    .add('奖牌榜',nodes_list,links_list,itemstyle_opts=opts.ItemStyleOpts(color="#decbe4"),linestyle_opt=opts.LineStyleOpts(opacity=0.5,curve=0.5,color='#b3cde3'),label_opts=opts.LabelOpts(position='right'),focus_node_adjacency=True,pos_top="10%")
    .set_global_opts(title_opts=opts.TitleOpts(title='2022北京冬奥会奖牌榜',subtitle='2022/02/04-2022/02/20'),tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"))
    .render('sankey.html')
)

Ⅲ.效果 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值