Skip to content

Bug - Links Change Specified Node Positions And Labels In Sankey Diagram #3452

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
collinpu opened this issue Nov 5, 2021 · 1 comment
Closed

Comments

@collinpu
Copy link

collinpu commented Nov 5, 2021

Hi,

I am using Plotly 5.3.1 in Python 3.6.5 on Ubuntu 16.04 using jupyter notebook 5.6.0.

I am defining node locations for a Sankey diagram. I found that adding or removing links causes some nodes to move from their specified locations to seemingly random new locations and node labels to change.

Below is a toy example that should illustrate these bugs. Note that from one run to the next some node labels change and that some nodes have moved in the image with all the random links (bottom middle for example). Also, just for clarity, I did not change the node or link sizes or colorings from one run to the next, that just happened automatically as I increased the number of random links.

"Importing and defining random node locations and links"
import numpy as np
import plotly.graph_objects as go
numNodes = 100
np.random.seed(1)
xValues = np.random.sample(numNodes)
yValues = np.random.sample(numNodes)
sources = list(np.random.randint(0,numNodes,(numNodes,)))
targets = list(np.random.randint(0,numNodes,(numNodes,)))

"""Function to visualize Sankey with a specified number of random links
All other nodes will have links to themselves so they are visible in the diagram
In my actual code there are no nodes with links to themselves, I just used this as a hack for this example"""
def VisualizeSankeyWithNumEdges(numEdges):
fig = go.Figure(go.Sankey(
arrangement = "fixed",
node = {
"label": [f'Node_{idx}' for idx in range(numNodes)],
"x": xValues,
"y": yValues},
link = {
"source": sources[:numEdges] + list(range(numNodes))[numEdges:],
"target": targets[:numEdges] + list(range(numNodes))[numEdges:],
"value": [1 for idx in range(numNodes)]}),
)
fig.update_layout(
autosize=False,
width=1000,
height=1000,)
fig.show()

VisualizeSankeyWithNumEdges(0) # Initial node placements and labels
InitialNodePlacements
VisualizeSankeyWithNumEdges(1) # Node labels incremented by 1. Node labels do increment with more random links, but not all nodes increment every time, and sometimes adding new random links doesn't increment the labels. Nodes with incremented labels will gain or lose links depending on what their new label is.
NewNodePlacements
VisualizeSankeyWithNumEdges(numNodes) # Final node placements and labeling. Note how nodes in the bottom middle have moved or disappeared compared to the initial picture (exp Node_94 in the initial picture). Just to clarify, I did not change any node or link size or color parameters, that happened automatically as I increased the number of random links.
NodePlacementsWithAllEdges

@collinpu collinpu changed the title Bug - Links Overwrite Specified Node Positions And Labels In Sankey Diagram Bug - Links Change Specified Node Positions And Labels In Sankey Diagram Nov 5, 2021
@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and 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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants