sankey图表python

6ioyuze2  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(296)

我试图用python制作一个sankey图表,如下所示:

但我有麻烦,因为它使循环,你可以看到:

我做错什么了?
我的剧本是:

import plotly.graph_objects as go

fig = go.Figure(data=[go.Sankey(
      node = dict(
      pad = 15,
      thickness = 20,
      line = dict(color = "black", width = 0.5),
      label = ["A1", "A2", "A3", "A4", "A5", "A4", "A2", "A6", "A3", "A5"], 
      color = "blue"
    ),
    link = dict(source = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4],
                target = [0, 6, 8, 5, 9, 3, 1, 7, 2, 4], 
                value =  [951, 795, 469, 408, 320, 1507 ,327 ,295, 288, 232] 
  ))])

fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
fig.show()
zbdgwd5y

zbdgwd5y1#

将源列表的第1个值与目标列表的第1个值、源列表的第2个值与目标列表的第2个值进行绘图连接,等等。。
这意味着画了以下几条线:
从0(a1)0(a1)回路1(a2)6(a2)2(a3)8(a3)3(a4)5(a5)4(a5)9(a5)0(a1)3(a3)1(a2)1(a2)回路2(a3)7(a6)3(a4)2(a3)4(a5)4(a5)回路
如您所见,从a1(idx 0)到a1(idx 0)、从a2(idx 1)到a2(idx 1)以及从a5(idx 4)到a5(idx 4)绘制线。

相关问题