【问题标题】:How do I colour the individual categories in a holoviews Sankey diagram?如何为 holoviews 桑基图中的各个类别着色?
【发布时间】:2019-07-17 23:03:07
【问题描述】:

我正在修改文档中的示例:http://holoviews.org/reference/elements/bokeh/Sankey.html

我希望能够访问每个类别并明确地为它们着色。例如/将“A”设为黄色、“B”设为蓝色等。我很乐意提供十六进制代码。

我在任何地方都找不到答案:文档、github 问题或以前的问题。我发现的最接近的是:Colour the links between nodes in sankey diagram: networkD3 因为 holoviews Sankey 是其中的一个端口,但我无法弄清楚它如何应用于 holoviews 实现。

上面链接中的代码

import holoviews as hv
from holoviews import opts, dim
hv.extension('bokeh')
sankey = hv.Sankey([
       ['A', 'X', 5],
       ['A', 'Y', 7],
       ['A', 'Z', 6],
       ['B', 'X', 2],
       ['B', 'Y', 9],
       ['B', 'Z', 4]]
)
sankey.opts(width=600, height=400)

我将如何更改上述内容以明确地为 A、B、X、Y、Z 着色?

谢谢

【问题讨论】:

    标签: styling sankey-diagram holoviews


    【解决方案1】:

    http://holoviews.org/user_guide/Styling_Plots.html#Explicit%20color%20mapping

    from holoviews.plotting.util import process_cmap
    
    cmap_list = process_cmap("glasbey_hv")
    cmap = {
        "A": cmap_list[0], # or 'yellow', 'blue', etc
        "B": cmap_list[1],
        "X": cmap_list[2],
        "Y": cmap_list[3],
        "Z": cmap_list[4],
    }
    
    sankey.opts(width=600, height=400, cmap=cmap)
    

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 1970-01-01
      • 2022-10-06
      • 1970-01-01
      • 2019-10-24
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多