Ⅰ.原始数据

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')
)

Ⅲ.效果 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐