Sankey and wrong x,y positions

I am trying to use x,y to position the elements of my sankey diagram.

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)

From the x,y positions, we should have A,B,C,D and E nodes all aligned vertically (they are all at x=0.0) with one below the other (as y coordinates are increasing for each node).
However, this is what I see (C not aligned with A,B,D and E + order of nodes not respected as A comes last).

Am I misunderstanding the logic of x,y in sankey diagrams ?

In my production setup, I also see in the console the following warning (I can’t see in my isolated example here above)

async-plotlyjs.v1_12_1m1600286997.js:2 WARN: ignored xaxis.scaleanchor: β€œy” to avoid either an infinite loop and possibly inconsistent scaleratios, or because the target axis has fixed range or this axis declares a matches constraint.

4 Likes

hi, did you manage to get the order as you expected?

Struggling with the same. The x and y in the chart does not match the provide values.

I have written a couple of articles on Medium about this. I don’t want to dig into this problem yet as I am stuck in something else. if you are interested, the article is here Further Adventures in Plotly Sankey Diagrams | by Tom Welsh | Medium with a link to the first article in the first few paragraphs. hopefully, it will help you out. I * Specifying X and Y coordinates for nodes

Regards

Tom