【发布时间】:2021-07-13 14:16:50
【问题描述】:
所以我正在尝试绘制一个 sankey,它应该显示 13 个源节点到 4 个不同的目标节点,但我不知道为什么它没有显示 13 个而只显示 6 个?这是我的代码和输出。它成功地绘制了所有 4 个目标节点,但只有 6 个源节点和一个非常奇怪的顺序。它绘制了“test”(第一个节点)、“test3”(第 4 个节点)、“test7”、“test10”、“test12”、“test8”。
import plotly.graph_objects as go
source = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
target = [13, 13, 13, 14, 14, 14, 14, 15, 16, 16, 16, 16, 16]
value = [1.5731754916099199, 0.0, -0.6622546030040232, 0.1803752820589049, -0.12705291484645911, -0.11239581604114621, -0.33000230488318316, 0.10184310050452802, 0.23013722041176082, -0.052664676881438124, 85.1250672340013, -0.006987341636945739, 11.9843590360198]
labels = ["test", 'test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7', 'test8', 'test9', 'test10', 'test11', 'test12', 'TARGET1', 'TARGET2', 'TARGET3', 'TARGET4']
link = dict(source=source, target=target, value=value)
node = dict(label=labels, pad=35, thickness=10)
data = go.Sankey( textfont=dict(color="rgba(0,0,0,0)", size=1), link=link, node=node)
fig = go.Figure(data)
fig.update_layout(
hovermode = 'x',
title="Sankey",
font=dict(size=8, color='white'),
paper_bgcolor='#51504f'
)
fig.show()
【问题讨论】:
标签: python python-3.x plotly plotly-python sankey-diagram