簡體   English   中英

如何在 plotly (python) sankey 中顯示圖例?

[英]How to show a legend in plotly (python) sankey?

我想 plot 一些代表不同物質質量流量的桑基圖報告。 我想放一個圖例來區分這些物質,但我不知道該怎么做。 我試過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 痕跡實際上並不支持圖例,盡管目前的文檔似乎表明它們確實支持。

我在 Plotly 存儲庫上創建了相應的問題 看起來該決議可能正在改進文檔以使其更清晰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM