holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

Colour the sankey diagram categories #3832

Open blakat360 opened 5 years ago

blakat360 commented 5 years ago

First time I do this so I apologise if I've done something wrong.

I have a sankey diagram and want to assign a specific colour to each of the start/end points.

eg/ make all blocks of category 'A' white and all 'B' yellow. I want to declare this explicitly for each block that's generated.

Is this doable? If so, how?

poplarShift commented 5 years ago

You should normally be able to specify a dim transform for any styling option, including node_color. However those options don't seem to be currently applied - I've opened #3835 for that.

For dim transforms, see here: http://holoviews.org/user_guide/Style_Mapping.html

jnettels commented 2 years ago

Doing the following works for me and achieves what I think you are describing:

with a DataFrame edges like this:

  From To  Value
0    A  X      5
1    A  Y      7
2    A  Z      6
3    B  X      2
4    B  Y      9
5    B  Z      4

this should work for defining specific colours:

explicit_mapping = {'A': 'blue', 'B': 'red', 'C': 'green', 'D': 'purple'}
hv_sankey = hv.Sankey(edges).options(
        edge_color_index='From'
        cmap=explicit_mapping,
        )

Blocks with undefined colour (X, Y, and Z) will be grey.