1

I'm modifying the example from the docs: http://holoviews.org/reference/elements/bokeh/Sankey.html

I want to be able to access each of the categories and colour them explicitly. Eg/ make 'A' yellow, 'B' blue etc. I'm happy to provide hex codes.

I can't find an answer anywhere: docs, github issues or previous questions. The closest thing I found was this: Colour the links between nodes in sankey diagram: networkD3 as the holoviews Sankey is a port of that but I can't figure out how that applies to the holoviews implementation.

The code from the link above

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)

How would I change the above to explicitly colour A,B,X,Y,Z?

Thanks

Edward
  • 468
  • 4
  • 18

1 Answers1

2

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)
Nuno Silva
  • 108
  • 10