Skip to content

Sankey diagram breaks depending on the order of the trace. #1536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adurivault opened this issue Apr 26, 2019 · 2 comments
Closed

Sankey diagram breaks depending on the order of the trace. #1536

adurivault opened this issue Apr 26, 2019 · 2 comments
Labels
bug something broken

Comments

@adurivault
Copy link

I'm trying to plot a Sankey diagram, and it breaks. Below is the simplest example with which I managed to reproduce the issue. Might be the same issue as #962, but I'm not using any subplot.

import plotly
import plotly.graph_objs as go

plotly.offline.plot(
    {
        "data": [
            go.Sankey(
                node=dict(
                    label=[1, 2, 3, 4, 5],
                    color=["blue", "blue", "blue", "blue", "blue"],
                ),
                link=dict(
                    source=[3, 3, 5, 3, 4, 1, 2, 1],
                    target=[1, 5, 3, 4, 3, 5, 3, 2],
                    value=[1, 1, 1, 1, 1, 1, 1, 1],
                ),
            )
        ]
    },
    auto_open=True,
)

When changing the order of the links, it works.

import plotly
import plotly.graph_objs as go

plotly.offline.plot(
    {
        "data": [
            go.Sankey(
                node=dict(
                    label=[1, 2, 3, 4, 5],
                    color=["blue", "blue", "blue", "blue", "blue"],
                ),
                link=dict(
                    source=[1, 3, 3, 5, 3, 4, 1, 2],
                    target=[2, 1, 5, 3, 4, 3, 5, 3],
                    value=[1, 1, 1, 1, 1, 1, 1, 1],
                ),
            )
        ]
    },
    auto_open=True,
)
@jonmmease
Copy link
Contributor

Thanks a lot for the report @adurivault.

I reproduced the issue in JavaScript and opened plotly/plotly.js#3813 to discuss with the Plotly.js folks.

This wasn't a cause of the error, but in case it wasn't clear to you I wanted to point out that the source and target arrays are zero-based indexes into the node.label array. So a source/target index of 1 will refer to the second node, the one with label "2" in your case. And the source/target index of 5 will refer to the 6th node, but since you only have 5 nodes this will result in a new black node with no label showing up in the diagram.

@gvwilson
Copy link
Contributor

Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

3 participants