[英]Colab: Python and Sankey in Plotly
我有一些簡單的代碼來測試桑基圖。 在將最后一個“合並”流渲染到最后一個節點之前,它似乎停止了。 有什么幫助/建議嗎?
import plotly.graph_objs as go1
# one merged line - CORP01 bought CORP02
# second, occurring after first M&A - CORP04 buys CORP03
# third, occuring after second M&A - CORP04 buys CORP01
# data
source = [0,1,2,3,4,4,5,6,7,7,8,8]
target = [4,4,5,6,7,7,8,8,9,9,9,9]
# data to dict, dict to sankey
link = dict(source = source, target = target, value = value)
label = ["CORP01", #source "0"
"CORP02", #source "1"
"CORP03", #source "2"
"CORP04", #source "3"
"CORP01m", #target "4" / source "4"
"CORP03a", #target "5" / source "5"
"CORP04a", #target "6"
"CORP01m2", #target "7" / source "7"
"CORP04m", #target "8" / source "8"
"CORP04m2"] #target "9"
node = dict(label = label, pad=20, thickness=10)
data = go1.Sankey(link = link, node=node)
# plot
fig = go1.Figure(data)
fig.show(renderer="colab")
該圖表一直有效,直到最后兩個流預計合並到最終的單個節點中。 有什么想法嗎?
根據 streetster 的信息 - 我忽略了添加一個列表來解決 Sankey 人物的value
。
通過添加value
列表,圖表完美呈現。
# data
source = [0,1,2,3,4,4,5,6,7,7,8,8]
target = [4,4,5,6,7,7,8,8,9,9,9,9]
value = [2,2,2,2,2,2,2,2,2,2,2,2]
# data to dict, dict to sankey
link = dict(source = source, target = target, value = value)
label = ["CORP01", #source "0"
"CORP02", #source "1"
"CORP03", #source "2"
"CORP04", #source "3"
"CORP01m", #target "4" / source "4"
"CORP03a", #target "5" / source "5"
"CORP04a", #target "6"
"CORP01m2", #target "7" / source "7"
"CORP04m", #target "8" / source "8"
"CORP04m2"] #target "9"
node = dict(label = label, pad=20, thickness=10)
data = go1.Sankey(link = link, node=node)
# plot
fig = go1.Figure(data)
fig.show(renderer="colab")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.