如何在plotly(python)sankey中显示图例?
我想为一份报告绘制一些代表不同物质质量流的sankey图表。我想用图例来区分这些物质,但我不知道怎么做。我尝试了如何在plotly(python)sankey中显示图例?,python,plotly,sankey-diagram,Python,Plotly,Sankey Diagram,我想为一份报告绘制一些代表不同物质质量流的sankey图表。我想用图例来区分这些物质,但我不知道怎么做。我尝试了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),
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()
尽管文档目前似乎表明它们确实支持图例,但Plotly Sankey traces似乎并不支持图例 我已经在Plotly repo上创建了;看起来,该决议可能会改进文档以使其更清晰