Python Plotly Sankey Graph not showing up



想知道是否有人可以帮助弄清楚为什么这个桑基图不起作用。我很确定我遵循了正确的语法和约定来使用该模块。因为这个,我的头一直在敲桌子。

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)

问题是这样的:

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

您不能让源和目标扮演双重角色,即:节点 1 既是源又是目标。

根据您的用例,您可能需要将其拆分。

对我来说,这是一个网络产品,所以我将我的节点拆分为"RX"和"TX",这样我就不会将源/目标数据列表加倍。

最新更新