The graph looks messy and barely recognize anything. I only want it to show the name of nodes with high centrality, but I don't know how. I can only show all the names now.
Graph:the result of the following codes
G_D=nx.Graph() G_D.add_edges_from(G5.edges(data=True))
nx.draw(G_D,nx.spring_layout(G_D),node_size=[v * 10 for v in df.iloc[:,0]],with_labels= True)
nx.draw
has an argument labels , which in combination with with_labels=True
can draw only labels you want, only how you want.
labels (dictionary, optional (default=None)) – Node labels in a dictionary keyed by node of text labels
For example, you can pick nodes 'label'
parameter and draw labels for nodes that have 3 or more neighbours:
labels = {
n: (G.nodes[n]['label']
if len(list(nx.all_neighbors(G, n))) > 2
else '')
for n in G.nodes
}
nx.draw(G, with_labels=True, labels=labels)
PS I don't recommend to use basic networkx drawing functional. There are many powerful visualization libraries better than networkx. Even in networkx docs you can find the same opinion. One can use Gephi , Graphviz (with various libraries) or Cytoscape for really HUGE graphs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.