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

Open
banderlog opened this issue Jan 4, 2021 · 0 comments
Open

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

banderlog opened this issue Jan 4, 2021 · 0 comments

Comments

@banderlog
Copy link

banderlog commented Jan 4, 2021

  1. We need to define both x and y or nothing will work Sankey node x and y positions require both variables set to reflect in chart. #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.

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

1 participant