Skip to content
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

Sankey node x and y positions could not be equal to 0 or np.nan #3002

Closed
banderlog opened this issue Jan 4, 2021 · 4 comments
Closed

Sankey node x and y positions could not be equal to 0 or np.nan #3002

banderlog opened this issue Jan 4, 2021 · 4 comments

Comments

@banderlog
Copy link

banderlog commented Jan 4, 2021

  1. We need to define both x and y or nothing will work allow provision of X coordinates only for Sankey charts #1732
  2. We cannot maintain the original position of a node (in R one could just add NA to that vector position)
  3. x and/or y should not be equal exactly to 0

Consider example below

# example from <https://plotly.com/python/sankey-diagram/>
import plotly.graph_objects as go

fig = go.Figure(data=[go.Sankey(
    arrangement = "perpendicular",
    node = dict(
      pad = 15,
      thickness = 20,
      line = dict(color = "black", width = 0.5),
      label = ["A1", "A2", "B1", "B2", "C1", "C2"],
      color = "blue",
    ),
    link = dict(
      source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A1, B1, ...
      target = [2, 3, 3, 4, 4, 5],
      value = [8, 4, 2, 8, 4, 2]
  ))])

fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
fig.show()

image

Now we want to put A2, B2, C2 before A1,B1,C1 on Y axis:

fig.data[0].node.x = [0., 0., 0.5, 0.5, 1, 1]
fig.data[0].node.y = [1, 0.5, 1, 0.5, 1, 0.5]
fig.show()

image

We are able to see that A1 and A2 did not change their places. That because they have 0 in x coordinates.
It is easy to fix:

fig.data[0].node.x = [1e-09, 1e-09, 0.5, 0.5, 1, 1]

We are not reloading Ys, just fixing Xs is enough.
Probably plotly.js problem on visualization, but plotly.python problem for letting this.

image

If we will do something like fig.data[0].node.x = [np.nan, 1e-09, 0.5, 0.5, 1, 1], A1 will behave in the same way as if it would be a 0.

@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

@egberts
Copy link

egberts commented Aug 22, 2024

Reopen it.

@banderlog
Copy link
Author

Still there, no surprise, because nothing changed in aforementioned index problem

@avm19
Copy link

avm19 commented Jan 10, 2025

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

@gvwilson Still an issue in version '5.22.0'.

This is a duplicate of #2902, although this issue's author provided a nice analysis and summary.

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

4 participants