1

I am trying to plot Sankey diagrams using Plotly's Sankey functionality. I can get Sankey diagrams to plot properly unless they contain loops (i.e. one state flows back into itself). When a loop occurs the chart sometimes gets cut off in the plot.

Example:

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

enter image description here

Notice how the circle is being cut off. I would like to have the plot show the complete circle, is there a way to do this? I have tried adding padding and increasing the size of the plot none of which has resolved the cut off issue.

Arthur Putnam
  • 1,026
  • 1
  • 9
  • 26

1 Answers1

2

You can improve this by specifying the height and width directly in the layout specification. I set the values manually.

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

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32