plotly / plotly/plotly.py

Weird Sankey cycles when nodes are positionned and not ordered by increasing x values

Open
#3,568 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.