Reputation: 1043
I created a Sankey diagram with Plotly but I don't understand the behaviour.
import plotly.graph_objects as go
fig = go.Figure(go.Sankey(
arrangement = "snap",
node = {
"label": ['F1', 'F2'],
'pad':10
},
link = {
"source": [1,2],
"target": [0,0],
"value": [1,1]
}))
fig.show()
fig.write_image('output.png')
The output is:
... I've specified two flows. Both have the same target node (0). So far so good. But why does the label of one flow show up next to the source node and the label of the other flow shows up next to the target node? I would expect both labels to be displayed next to the nodes on the left hand side and not one label next to the node on the left hand side and one label next to the node on the right hand side.
Why are both labels not displayed next to the two nodes on the left hand side?
Upvotes: 0
Views: 2102
Reputation: 1471
I think that the labels are not displayed next to the node because it is also considering the source node when you are defining the labels, so by simply removing the first value (by making it an empty string), you can accomplish what you are looking for.
import plotly.graph_objects as go
fig = go.Figure(go.Sankey(
arrangement = "snap",
node = {
"label": ['', 'F1', 'F2'],
'pad':10
},
link = {
"source": [1,2,],
"target": [0,0],
"value": [1,1]
}))
fig.show()
Upvotes: 2