Avoiding Sankey diagram vertical overlap?

Iโ€™m making a simple view of the ownership of a property over time where owners have sold their interests in the land to other owners. However, the vertical spacing of the flows is off and they overlap. In this example, Mallory sells 100% of the land to Alice (50%) and Bob (50%), and then later Bob sells his 50% to Alice. What I would like to have is something like:

But what I get is:

Iโ€™ve tried setting x and y options but I canโ€™t seem to make a difference in the view. is there a different option I should be using?

Relevant code:

fig = go.Figure(data=[go.Sankey(
    arrangement = "snap",
    node = {
      'pad':15,
      "thickness":20,
      "line":dict(color = "black", width = 0.5),
      "label":["Mallory","Alice", "Bob"],
      "color":'blue'
    },
    link = {
      "source":[0, 0, 2],
      "target":[1, 2, 1],
      "value":[50, 50, 50],
 })]);
fig.update_layout(title_text="Land Ownership", font_size=10);
fig.show();

Thanks!

Hi @mjbraun ,

Welcome to the forum !

I have tried to reproduce your code and adding specific node position, and fortunately I can generate like first image.

import plotly.graph_objects as go

fig = go.Figure(data=[go.Sankey(
    arrangement = "snap",
    node = {
      'pad':15,
      "thickness":20,
      "line":dict(color = "black", width = 0.5),
      "label":["Mallory","Alice", "Bob"],
      "x": [0.1, 0.5, 0.3, ], 
      "y": [0.5, 0.2, 0.8,],
      "color":'blue'
    },
    link = {
      "source":[0, 0, 2],
      "target":[1, 2, 1],
      "value":[50, 50, 50],
 })])
fig.update_layout(title_text="Land Ownership", font_size=10)
fig.show()

@farispriadi Thank you! I had initially tried

      "x":[0.2, 0.1, 0.5],
      "y":[0.7,0.5,0.2]

Which made the chart look bonkers so I assumed adjusting the x and y was not the right course to be on but it looks like I just needed to experiment to find the sweet spot.

1 Like