本文介绍了Python Plotly Sankey图未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想知道是否有人可以帮忙弄清楚为什么这个Sankey图不起作用.我很确定我遵循正确的语法和约定来使用该模块.正因为如此,我一直在桌子上摔我的头.
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)
推荐答案
问题是这样的:
'source': [1, 3],
'target': [3, 1]
您不能让源和目标同时扮演双重角色,即:节点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.
对于我来说,这是关于一种网络产品的,所以我将节点分为"RX"和"TX",所以我不会将源/目标数据列表加倍.
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.
这篇关于Python Plotly Sankey图未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!