Holoviews: how to generate legend for node colors in network plot

53 Views Asked by At

Using holoviews for showing network diagrams, I want to show a legend for the node colors so the viewer does not have to hover to see the type of node. For example with this code I want a legend indicating what 'type' the node color represents.

K = nx.karate_club_graph()
node_type = np.array(['type1']*17 + ['type2']*17).reshape(34)

for i, _ in enumerate(K.nodes()):
    K.nodes[i]['type'] = node_type[i]
    
hv.Graph.from_networkx(K, nx.layout.fruchterman_reingold_layout,k=.3).opts(tools=['hover','tap'],
                                                                          node_size=10,
                                                                          node_color='type',
                                                                          cmap = 'Category10',
                                                                          show_legend = True)

I can put labels on the nodes but it gets very messy and illegible. I can explicitly construct the legend for the colours but that is impractical except in a very simple graph. How can this be done?

0

There are 0 best solutions below