【问题标题】:Why is plotly's sankey diagram not plotting all my source nodes?为什么 plotly 的 sankey 图没有绘制我所有的源节点?
【发布时间】: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


    【解决方案1】:

    问题是我的 sankey 值列表中有负值。你显然不能这样做。如果您尝试使用负百分比的饼图(它只是不起作用或看起来不错),这是一个类似的问题。为了解决我的问题,我在标签上添加了一个负号,然后对所有负数进行绝对值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 1970-01-01
      • 2018-07-28
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2020-06-03
      相关资源
      最近更新 更多