簡體   English   中英

如何在 python 中使用 networkx 向圓形圖中的節點添加標簽

[英]How to add labels to nodes in a CIRCULAR GRAPH with networkx in python

我正在使用以下方法繪制圓形圖:

nx.draw_circular(G, node_color='b', edge_color='#909090', node_size=500)

基本上我想要做的是為節點添加標簽,但我找不到在這種類型的圖中添加它們的方法。 我嘗試使用:

nx.draw_networkx_labels(G,labels=labels,pos=nx.spring_layout(G),font_size=16)

但是位置布局有問題,不是next/in每個節點。

在此處輸入圖像描述

解決了!

G=nx.Graph()
G.add_nodes_from(range(20))
e = [(0,1),(0,2)]
G.add_edges_from(e)

# some labels
labels={}

nx.draw_circular(G, node_color='y', edge_color='#909090', node_size=500,labels=labels)

plt.axis('equal')

在此處輸入圖像描述

draw_networkx_labels()函數與nx.circular_layout() pos nx.circular_layout()

G = nx.Graph()
e = [(0, 1), (0, 2)]
G.add_edges_from(e)

pos = nx.circular_layout(G)
nx.draw_networkx_labels(G, pos)
nx.draw_circular(G, node_color='#2ea28a', node_size=1000)

plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM