-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
go.Sankey not respecting (x,y) coordinates #2902
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
Comments
I see you have five nodes with x=0.0 and one with x=1.0. For my Plotly app I'm writing functions that generate x and y coordinates for a go.Sankey, and if some numbers that come out of them happen to be 0.0 or 1.0 the nodes go haywire similarly to what you have in your screenshot. If you replace your 0.0s by some arbitrarily small positive number and your 1.0s by some number arbitrarily close to 1.0, does it circumvent the bug? |
Indeed, thank you! |
Hi! I haven't found a way to force an ordering in the Sankey links through the In the project I worked on, which dealt with years of study (1º through 12º), the Sankey diagram eventually started to mix them up But I have been reading some source code for a little bit. Many visualizations implemented in Plotly.js use the D3.js library, including Sankey, which uses the d3-sankey module. So, I think that Plotly's Sankey diagrams could respect the order of links and nodes in the dataframe, but I think that at the moment Plotly doesn't provides us the options to do so. I wasn't able to pinpoint where exactly the order is getting mangled yet. I wonder if it is a good idea to open a new issue asking for new sorting attributes in |
Hi @diogotito, thank you for your feedback. |
I am experiencing this even without any 0's code to repro here import plotly.graph_objects as go
x = [0.06101736788793636, 0.23475059910566495, 0.23475059910566495, 0.23475059910566495, 0.43176371766682314, 0.43176371766682314, 0.43176371766682314, 0.6881809422635077, 0.6881809422635077, 0.6881809422635077, 0.6881809422635077, 0.6881809422635077, 0.6881809422635077, 1.0]
y = [0.22857142857142856, 0.4, 0.22857142857142856, 0.05714285714285714, 0.5714285714285714, 0.4, 0.22857142857142856, 1.0, 0.8285714285714286, 0.6571428571428571, 0.4857142857142857, 0.3142857142857143, 0.14285714285714285, 0.7428571428571429]
labels = list(map(str, (range(len(x)))))
colors = 'blue'
source_links = (0, 0, 0, 1, 1, 1, 4, 4, 4, 4, 4, 4, 10, 7)
target_links = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13)
values = [19890, 20082, 60028, 4262, 15628, 0, 815, 887, 2560, 859, 853, 2550, 1504, 1504]
fig = go.Figure(data=[go.Sankey(
arrangement = "fixed",
node = dict(
# pad = 15,
# thickness = 20,
line = dict(color = "black", width = 0.5),
label = labels,
color = colors,
x=x,
y=y
),
link = dict(
source = source_links,
target = target_links,
value = values,
label = values,
))])
fig.update_layout(title_text="repro", font_size=10)
fig.show() comes out like this but should look like this |
@mk-oliver-s Everything except the last node (13) works as intended by developers: y coordinates define the centre of the node from the top. So flip the graph upside down and make all |
The code below
generates

which is not expected as:
I may have misunderstood the (x,y) coordinates logic or it is a bug...
Libraries version:
plotly==4.9.0
dash==1.16.3
dash-core-components==1.12.1
dash-html-components==1.1.1
The text was updated successfully, but these errors were encountered: