So I realise that this is quite a specific question, but it's been bugging me for ages and I can't seem to find a solution..
I am using Plotly with Python to produce Sankey diagrams. I have the following source, target, and value figures:
source target value
0 0.0 5.0 1.0
1 0.0 6.0 1.0
2 1.0 6.0 1.0
3 2.0 7.0 1.0
4 3.0 8.0 1.0
5 4.0 8.0 1.0
6 5.0 9.0 1.0
7 6.0 10.0 1.0
8 7.0 9.0 1.0
9 8.0 9.0 1.0
10 9.0 11.0 1.0
11 9.0 12.0 1.0
12 9.0 13.0 1.0
13 10.0 13.0 1.0
14 10.0 14.0 1.0
15 11.0 15.0 1.0
16 12.0 15.0 1.0
17 12.0 16.0 1.0
18 13.0 16.0 1.0
19 14.0 17.0 1.0
20 15.0 18.0 1.0
21 15.0 19.0 1.0
22 16.0 18.0 1.0
23 17.0 19.0 1.0
Which produce the following unsmoothed Sankey diagram
However, you can see that some of the connecting lines are not the same as the corresponding nodes (e.g. the line flowing out of node i is shorter than node i).
Annoyingly, Plotly doesn't seem to give you the option to automatically smooth the node-line height differences. You can do this manually with simple diagrams, but it's virtually impossible with complex ones like the one I've attached - altering the heights in one section mean you have to alter the heights elsewhere, etc. because everything is so interconnected
Do you know how I can calculate 'value' figures based on the 'source' and 'target' lists, such that you get perfect smoothing across all nodes and lines? (e.g. like this one smoothed Sankey diagram)
I feel there must an algorithm that will give a perfect solution no matter what the source and target lists look like, but I can't figure it out..
EDIT:
the code to create the image is:
link = dict(source = source, target = target, value = value_ones)
node = dict(label = label, pad=50, thickness=5)
data = go.Sankey(link = link, node=node)
fig = go.Figure(data)
fig.show()
label is just a dictionary of unique source values and ascending numbers 0-19