import plotly.graph_objects as go

# 定义节点和边
NAME_1 = [
    {'node': 0, 'label': 'A'}, 
    {'node': 1, 'label': 'B'}, 
    {'node': 2, 'label': 'C'}, 
    {'node': 3, 'label': 'D'}
]

links = [
    {'source': 0, 'target': 1, 'value': 10}, 
    {'source': 0, 'target': 2, 'value': 20}, 
    {'source': 0, 'target': 3, 'value': 30},
    {'source': 1, 'target': 3, 'value': 40}, 
    {'source': 2, 'target': 3, 'value': 50}
]

# 创建图形
fig = go.Figure(data=[go.Sankey(
    node=dict(
        pad=15,
        thickness=20,
        line=dict(width=0.5),
        label=[n['label'] for n in NAME_1],
        color='blue'
    ),
    link=dict(
        source=[l['source'] for l in links],
        target=[l['target'] for l in links],
        value=[l['value'] for l in links]
    )
)])

# 设置布局
fig.update_layout(title_text="Sankey Diagram Example")

# 显示图形
fig.show() Respond with at most 800 words.
user