I have following code to visualize networkx graph:
node_positions = networkx.spring_layout(graph)
networkx.draw_networkx_nodes(graph, node_positions)
networkx.draw_networkx_edges(graph, node_positions, style='dashed')
I want to display node label on each node. graph.nodes()
will give me list of all the nodes but how can I use them to label nodes on the graph?
I tried this, but it is not working:
networkx.draw_networkx_labels(graph,node_positions,graph.nodes(data="false"),font_size=16)
EDIT:
I tried following and its working for now:
for node,_ in graph.nodes(data="False"):
labels[node] = node;
networkx.draw_networkx_labels(graph,node_positions,labels,font_size=16)
If there is still some elegant way to do it please let me know. I feel creating new dict is overkill, redundant and should not be required.