[Python] How to Color Target Nodes in Sankey Diagram Python using Plotly?

Discussão em 'Python' iniciado por Stack, Julho 8, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using plotly.graph_objects to build a Sankey diagram, and I'd like the target nodes to be the same color as the links that flow into them. An example of the code structure I have so far is:

    label = ['A', 'B', 'Z', 'Y', 'X']
    source = [0, 0, 0, 1, 1, 1]
    target = [2, 3, 4, 2, 3, 4]
    value = [100, 200, 300,
    400, 500, 600]
    link = dict(source = source, target = target, value = value, color = color) #colors have been defined for links in a different cell)
    node = dict(label = label, pad=35, thickness = 10)
    data = go.Sankey(link = link, node = node)
    fig=go.Figure(data)
    fig.show()


    This gets pretty close to what I want, but I need to be able to color the target nodes so they match the links.

    Thanks in advance,

    Continue reading...

Compartilhe esta Página