I am creating a Sankey diagram with plotly as follows:
import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(
valueformat = ".0f",
valuesuffix = " %",
orientation = "h",
node = dict(
pad = 20,
thickness = 20,
line = dict(color = "red", width = 1),
label = ['Equity',
'Global Equity',
'Tier 1',
'A looooooooooong',
'Tier 2',
'B looooooooooong',
'C looooooooooong',
'Tier 3',
'D looooooooooong',
'E looooooooooong',
'F looooooooooong',
'G looooooooooong',
'H looooooooooong'],
color = ['aqua',
'aqua',
'yellow',
'orange',
'yellow',
'orange',
'orange',
'yellow',
'orange',
'orange',
'orange',
'orange',
'orange'],
),
link = dict(
source = [0, 2, 1, 4, 4, 2, 7, 7, 7, 7, 7, 4],
target = [1, 3, 2, 5, 6, 4, 8, 9, 10, 11, 12, 7],
value = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
color = ['aqua',
'yellow',
'aqua',
'yellow',
'yellow',
'aqua',
'yellow',
'yellow',
'yellow',
'yellow',
'yellow',
'aqua'],
hovertemplate='This link has total value %{value}<extra></extra>'
))])
fig.update_layout(title_text="Waterfall Diagram",
font_size=16,
plot_bgcolor='white',
paper_bgcolor='white')
fig.show()
Output looks like this:
Is there a way:
- to make sure links in color aqua are always below the yellow ones? to visually separate them better - I am not sure why current set up show them in that order
- to give more space between the links, spreading them out more? Especially I would need links and nodes not to overlap each other
- spread out the aqua links even further? I.e. visually dissociate them from the others
- to control where and how node labels are shown? I.e. to the right or below node, and also controlling the font for each node