question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

go.Sankey not respecting (x,y) coordinates

See original GitHub issue

The code below

import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go
from dash import Dash

app = Dash(__name__)


def sankey():
    x = [0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 1.0]
    y = [
        0.21630069,
        0.47642676,
        0.54677235,
        0.62167333,
        0.74199201,
        0.29388136,
        0.73906564,
        0.89679547,
        0.95161119,
        0.29388135,
    ]
    label = list("ABCDEFGHIJ")

    source = [0, 1, 0, 1, 2, 2, 2, 2, 0, 1, 2, 2, 3, 4, 5, 6, 6, 8]
    target = [5, 5, 2, 2, 5, 5, 7, 7, 6, 6, 6, 6, 5, 5, 9, 9, 8, 9]
    value = [
        4.03086075e-02,
        3.13536457e-01,
        4.74989358e-03,
        4.82905398e-02,
        2.57156646e-03,
        2.55178406e-02,
        1.15108889e-03,
        1.17027262e-02,
        7.78313638e-03,
        7.07743914e-02,
        1.02723822e-03,
        1.10699730e-02,
        1.43875830e-01,
        6.19524093e-02,
        3.81934471e-01,
        2.05828238e-01,
        6.19685055e-02,
        2.53269630e-17,
    ]

    fig = go.Figure(
        data=[
            go.Sankey(
                arrangement="fixed",
                node=dict(
                    # thickness=20,
                    # line=dict(color="black", width=0.5),
                    label=label,
                    x=x,
                    y=y,
                ),
                link=dict(source=source, target=target, value=value),
            )
        ]
    )
    return fig


app.layout = html.Div([dcc.Graph(figure=sankey())])

if __name__ == "__main__":
    app.run_server(debug=True)

generates newplot (20) which is not expected as:

  • nodes A,B,C,D and E have all same x coordinates (should be aligned on same vertical line)
  • nodes A,B,C,D,E should be ordered from top to bottom as they have increasing y coordinates

I may have misunderstood the (x,y) coordinates logic or it is a bug…

Libraries version: plotly==4.9.0 dash==1.16.3 dash-core-components==1.12.1 dash-html-components==1.1.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
diogotitocommented, Nov 25, 2020

I see you have five nodes with x=0.0 and one with x=1.0.

For my Plotly app I’m writing functions that generate x and y coordinates for a go.Sankey, and if some numbers that come out of them happen to be 0.0 or 1.0 the nodes go haywire similarly to what you have in your screenshot. I fixed it for me by making the coordinates go from 0.01 to 0.99.

If you replace your 0.0s by some arbitrarily small positive number and your 1.0s by some number arbitrarily close to 1.0, does it circumvent the bug?

0reactions
JorgeMiguelGomescommented, Feb 22, 2022

Hi @diogotito, thank you for your feedback. After running some experiments I found out that the ordering is done by the value of passed to each node, as you can actually clearly see in the image I posted (I did other tests just to make sure). Opening an issue might might be a good idea, based on what you describe, yes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotly's Sankey diagram ignores X and Y coordinates
The problem I'm having with Plotly's Sankey visualisation (Python version) is that I believe the X and Y coordinates are being overriden by...
Read more >
Sankey and wrong x,y positions - Plotly Community Forum
I am trying to use x,y to position the elements of my sankey diagram. From the x,y positions, we should have A,B,C,D and...
Read more >
'Sankeying' with Plotly | Python in Plain English
How to make Sankey diagrams in Plotly. ... #Creating the Sankey figure fig = go.Figure(data=[go.Sankey( ... if(x+'_M'+str(i+1) not in names):
Read more >
Sankey – amCharts 5 Documentation
Sankey can be used (imported) via one of the following packages. ... Do not enable unless you are using such aggregate values in...
Read more >
Python Plotly tutorial - GeeksforGeeks
Plotly does not come built-in with Python. ... have created a simple line chart by passing the x, y coordinates of the points...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found