最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Understanding x and y coordinates in Plotly's Sankey Chart - Stack Overflow

programmeradmin0浏览0评论

I was trying to create a custom Sankey chart based on my defined x and y coordinates. However it isn't turning out as I am expecting.

I was expecting that the nodes would stick to the defined x values but it does not seem to be the case Consider the below case.

import plotly.graph_objects as go

fig = go.Figure(go.Sankey(
    arrangement='snap',
    node=dict(
        label=['A', 'B', 'C', 'D', 'E', 'F'],
        x=[0.01, 0.01, 0.01, 0.5, 0.99, 0.99],
        y=[0.01, 0.40, 0.5, 0.1, 0.01, 0.3],
        pad=10,
    ),
    link=dict(
        source=[0, 1, 2, 3, 3],
        target=[3, 3, 3, 4, 5],
        value=[40, 10, 50, 30, 70]
    )
))

fig.show()

I arrived at the y values by taking the cumulative percentage till the previous node for the plots made on a specific X axis [e.g. A = 0.01; B = 40/(40+10+50); C = (40+10)/(40+10+50)] Ideally as per the definitions I would expect the first node in the diagram to be A the second to be B and third to be C. Something like below

However it doesn't quite work like it. This is how it ends up looking instead, the first node is A second is C and third is B. C

Can you please help me understand what I'm supposedly doing wrong?

发布评论

评论列表(0)

  1. 暂无评论