Show color map or edge labels in hvnx.draw?

Is it possible to show a colorbar next to the graph returned by hvnx.draw(). In my panel application, I’ve got a graph which has different colors assigned to edges and nodes bases on some attributes. Is there a way to display a colormap to indicate the value of the edge or an edge label.

G = nx.Graph()

G.add_edge('a', 'b', weight=0.6)
G.add_edge('a', 'c', weight=0.2)
G.add_edge('c', 'd', weight=0.1)
G.add_edge('c', 'e', weight=0.7)
G.add_edge('c', 'f', weight=0.9)
G.add_edge('a', 'd', weight=0.3)

G.add_node('a', size=20)
G.add_node('b', size=10)
G.add_node('c', size=12)
G.add_node('d', size=5)
G.add_node('e', size=8)
G.add_node('f', size=3)

pos = nx.spring_layout(G)  # positions for all nodes

hvnx.draw(G, pos, edge_color='weight', edge_cmap='viridis',
          edge_width=hv.dim('weight')*10, node_size=hv.dim('size')*20)

This code is from link NetworkX — hvPlot 0.8.2 documentation
Thank you.

Seems like there is a bug in HoloViews preventing a colorbar from being rendered. I’ve fixed it here: Enable rendering colorbars on bokeh GraphPlots by philippjfr · Pull Request #5585 · holoviz/holoviews · GitHub

1 Like

Thank you very much @philippjfr. So to be able to make it work, what is needed locally for me? Secondly, I have node colors as well which i’m using ‘viridis’ colormap to differentiate but it’s a different scale. So is it possible to indicate that. And a last thing is whether I can make an edge dotted/dashed? I want to indicate a negative relationship. This is a bit extension of my original question. Apologies.

@philippjfr I see the pull request has been accepted, but when I run the code at my end it still doesn’t work. Do I have to update the package using pip?

Yes, but we have to release a new version. We hope to release 1.15.4 early next week.

1 Like