【问题标题】:Plotly Sankey chart cutting off when loops existsPlotly Sankey 图表在存在循环时切断
【发布时间】:2020-07-27 21:13:21
【问题描述】:

我正在尝试使用Plotly's 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()

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

【问题讨论】:

    标签: python plotly sankey-diagram


    【解决方案1】:

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

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-26
      • 2022-10-04
      • 2021-10-24
      • 2022-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多