Sankey: why are nodes misplaced?

Hi.
I am working with Sankeys, but I am quite confused about nodes automatic placement (alas I cannot place the nodes manually).

import plotly.graph_objects as go

sources = [ 0,  0,  1,  1,  2,  2]
targets = [ 1,  2,  3,  4,  5,  6]
values  = [45, 30, 15, 30, 20, 10]
labels = ['Node 0', 'Node 1', 'Node 2', 'Node 3', 'Node 4', 'Node 5', 'Node 6']

link = dict(source=sources, target=targets, value=values)
node = dict(label=labels)
data = go.Sankey(link=link, node=node)
fig = go.Figure(data)
fig.show(renderer="svg", width=1000, height=500)

produces
plotly_question1

Why is Node 3 misplaced, and is not together with Node 4?
Nodes are not placed according to sorted value, otherwise Node 3 should be below Node 6.

Just changing from 15 to 16 the weight of Node1->3 the placement is correct:

values  = [46, 30, 16, 30, 20, 10]

produces:
plotly_question2

Am I missing something here?

2 Likes