Python Plotly Sankey Graph not showing up

本小妞迷上赌 提交于 2019-12-08 06:40:37

问题


Was wondering if anyone can help figure out why this Sankey diagram is not working. I am pretty sure I followed the proper syntax and conventions to use the module. Been banging my head on the table because of this.

import plotly.offline

data_trace = {'domain': {'x': [0, 1], 'y': [0, 1]},
    'height': 772,
    'link': {'label': ['EM', 'GWF9C51E', 'GWF9C511', 'GWF9C51E Sensor Set',
                                'GWF9C511 Sensor Set'],
             'source': [0, 1, 3, 1, 4, 2, 0, 2],
             'target': [1, 3, 1, 0, 2, 0, 2, 4],
             'value': [40, 76, 29, 86, 30, 75, 41, 65]},
    'node': {'color': ['blue', 'yellow', 'yellow', 'green', 'green'],
             'label': ['EM', 'GWF9C51E', 'GWF9C511', 'GWF9C51E Sensor Set',
                      'GWF9C511 Sensor Set'],
             'line': {'color': 'black', 'width': 0.5},
             'pad': 15,
             'thickness': 15},
             'orientation': 'h',
             'type': 'sankey',
             'valueformat': '.3s',
             'valuesuffix': 'pkts',
             'width': 1118}
layout =  dict(
    title = "Testing Sankey",
    font = dict(
    size = 10
    )

fig = dict(data=[data_trace], layout=layout)
plotly.offline.plot(fig, validate=False)

回答1:


The problem is this:

         'source': [1, 3],
         'target': [3, 1]

You cant have the sources and target play double roles ie: node 1 is both a source and a target.

Depending on your use case, you might have to split it up.

For mine, this is about a networking product so I split up my nodes to 'RX' and 'TX' so I don't double up the source/target data list.



来源:https://stackoverflow.com/questions/50869718/python-plotly-sankey-graph-not-showing-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!