gpt4 book ai didi

python - 如何在 plotly (python) sankey 中显示图例?

转载 作者:行者123 更新时间:2023-12-04 14:17:35 26 4
gpt4 key购买 nike

我想为报告绘制一些代表不同物质质量流量的桑基图。我想放一个图例来区分物质,但我不知道该怎么做。我试过 showlegend没有成功

import plotly.graph_objects as go

fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = ['household','industry','waste'],
color = "blue"
),
link = dict(
source = [0,1,0,1], # indices correspond to labels, eg A1, A2, A2, B1, ...
target = [2,2,2,2],
value = [7190,2074,4483,74.50],
label = ['aluminium','aluminium','copper','copper'],
color = ['#d7d6d6','#d7d6d6','#f3cf07','#f3cf07']
))])
fig.update_layout(showlegend=True)
fig.show()

enter image description here

最佳答案

尽管目前的文档似乎表明它们确实支持图例,但似乎 Plotly Sankey 跟踪并不实际支持图例。

我创建了 a corresponding issue在 Plotly repo 中;看起来分辨率可能会改进文档以使其更清晰。

关于python - 如何在 plotly (python) sankey 中显示图例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58852056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com