0

How to show label outside the node in networkx graph

How to show label above the node in networkx

14th Apr 2020, 2:50 PM
Kulsum Ansari
1 Réponse
+ 2
Here a complete graph is drawn with 4 nodes then pos is used to get the x and y coordinates of the nodes in form of dictionary. Then pos_higher is used to manipulate the position of labels. A dictionary for labels is made and nx.draw_networkx_labels(G, pos_higher,labels) is used to plot labels on the previous drawn graph. Example: import networkx as nx G=nx.complete_graph(4) pos=nx.spring_layout(G) pos_higher = {} for k, v in pos.items(): if(v[1]>0): pos_higher[k] = (v[0]-0.1, v[1]+0.1) else: pos_higher[k] = (v[0]-0.1, v[1]-0.1) labels={0:'A',1:'B',2:'C',3:'D'} nx.draw(G) nx.draw_networkx_labels(G, pos_higher,labels)
21st Apr 2020, 7:17 PM
ashish tripathi
ashish tripathi - avatar