[英]Colab: Python and Sankey in Plotly
I've got some simple code to test Sankey charts.我有一些简单的代码来测试桑基图。 It seems to stop before rendering the last "merging" flows to the last node.在将最后一个“合并”流渲染到最后一个节点之前,它似乎停止了。 Any help / suggestions?有什么帮助/建议吗?
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")
The chart works until the last two flows are expected to merge into the final single node.该图表一直有效,直到最后两个流预计合并到最终的单个节点中。 Any thoughts?有什么想法吗?
As per the info from streetster - I neglected to add a list to address the value
for the Sankey figure.根据 streetster 的信息 - 我忽略了添加一个列表来解决 Sankey 人物的value
。
By adding a list for value
, the chart rendered perfectly.通过添加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.