桑基圖DEMO代碼

桑基圖DEMO代碼
代碼取自pyecharts.charts下sankey的example代碼。

nodes = [
	{'name': 'category1'},
	{'name': 'category2'}, 
	{'name': 'category3'},
    {'name': 'category4'}, 
    {'name': 'category5'}, 
    {'name': 'category6'},
]
#nodes需要把桑基圖中出現的名稱全部設置進去,並且要保證links中的名稱與name相同
links = [
    {'source': 'category1', 'target': 'category2', 'value': 10},
    {'source': 'category2', 'target': 'category3', 'value': 15},
    {'source': 'category3', 'target': 'category4', 'value': 20},
    {'source': 'category5', 'target': 'category6', 'value': 25}
]
#links代表節點關係,source表示起點,target表示終點,需要將節點關係全部輸入進去,value表示節點長度
from pyecharts import options as opts
from pyecharts.charts import Page, Sankey

sankey = Sankey()		#可以設置大小和圖標名稱
sankey.add(
    'sankey',				#名稱
    nodes,					#輸入節點,如果導入json數據,nodes=json['nodes]
    links,					#輸入關係,nodes=json['links']
    linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source", width=1600),
    label_opts=opts.LabelOpts(position="right", is_show=True, color='red'),
    node_gap=20
)
sankey.render()

運行的結果如下:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章