Weird Sankey cycles when nodes are positionned and not ordered by increasing x values
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.8k
- Avg merge
- 16h 26m
- Merged PRs (30d)
- 21
Description
I had some strange looking arrows in a Sankey (Plotly v 5.5.0), involving loops. The exact same problem was raised here. After trying different things, I found out the problem occured only when using node positions, and if the nodes in a given loop are not ordered by ascending 'x' position. You may give it a try with this very basic example:
import plotly.graph_objects as go
fig = go.Figure(go.Sankey(
node = {"label": ["First node", "Last node"],
"x": [0.6, 0.2],
"y": [0.2, 0.6]},
link = {
"source": [0, 1],
"target": [1, 0],
"value": [1, 1]
}))
fig.show()
And then replacing the "x" line by:
"x": [0.2, 0.6],
This looks like a bug, which should be fixed ideally. In the meantime, I strive to first order my nodes by ascending X position, which is rather tedious, since I already have to remove nodes without links (or 0 value links) as explained in other open issues. This involves quite a bit of pre-processing unfortunately.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Python Sankey example in the issue and compare the two node x-orderings. Trace the Sankey rendering path to identify why the reversed positions create broken loop arrows; done means both orderings render the cycle correctly without requiring callers to reorder nodes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100