当存在循环时,Plotly Sankey 图会被切断

Plotly Sankey chart cutting off when loops exists

我正在尝试使用 Plotly's Sankey 功能绘制桑基图。我可以让 Sankey 图正确绘制,除非它们包含循环(即一个状态流回自身)。当出现循环时,图表有时会在绘图中被截断。

示例:

fig = go.Figure(data=[go.Sankey(
    node = dict(
      pad = 0,
      thickness = 10,
      line = dict(color = "black", width = 0.5),
      label = ["A", "B", "C"],
      color = "blue"
    ),
    link = dict(
      source = [0, 0, 0 ],
      target = [0, 1, 0 ],
      value = [8, 4, 2 ]
  ))])

fig.update_layout(title_text="Cut off loop example", font_size=10)
fig.show()

注意圆是如何被切断的。我想让情节显示完整的圆圈,有没有办法做到这一点?我尝试添加填充并增加图的大小none,其中解决了截止问题。

您可以通过直接在布局规范中指定高度和宽度来改进这一点。我手动设置值。

import plotly.graph_objects as go

fig = go.Figure(data=[go.Sankey(
    node = dict(
      pad = 0,
      thickness = 10,
      line = dict(color = "black", width = 0.5),
      label = ["A", "B", "C"],
      color = "blue"
    ),
    link = dict(
      source = [0, 0, 0 ],
      target = [0, 1, 0 ],
      value = [8, 4, 2 ]
  ))])

fig.update_layout(title_text="Cut off loop example", font_size=10, width=1000, height=350)
fig.show()