[英]edge length labels in networkx are not well represented
這是關於搜索引擎 (SE) 的。 我試圖用圖表表示一個 SE 和其他 SE 之間的距離。 我給他們貼上了標簽:
DG.add_edge(se1, se2, length=distance[se1][se2])
然后到label的邊
nx.draw.networkx_edge_labels(DG, pos=pos, font_size=8)
但輸出非常不連貫:
樣本
[('AllTheInternet', 'Yippy', {'length': 0.727}),
('AOL', 'Yippy', {'length': 0.446}),
('Ask', 'Yippy', {'length': 0.88}),
('Bing', 'Yippy', {'length': 0.765}),
('DirectHit', 'Yippy', {'length': 0.733}),
('Duckduckgo', 'Yippy', {'length': 0.795}),
('Ecosia', 'Yippy', {'length': 0.793}),
('Google', 'Yippy', {'length': 0.852}),
('Lilo', 'Yippy', {'length': 0.43}),
('Lycos', 'Yippy', {'length': 0.766}),
('Qwant', 'Yippy', {'length': 0.834}),
('Startpage', 'Yippy', {'length': 0.77}),
('Teoma', 'Yippy', {'length': 0.776}),
('Yahoo', 'Yippy', {'length': 0.445})]
不確定您的哪一步導致了錯誤。 確保在繪制圖形時指定edgelist
,以防萬一。 否則,這可能會導致舊版本出現差異。 以下似乎按預期產生:
edgelist = [('AllTheInternet', 'Yippy', {'length': 0.727}), ('AOL', 'Yippy', {'length': 0.446}),
('Ask', 'Yippy', {'length': 0.88}), ('Bing', 'Yippy', {'length': 0.765}),
('DirectHit', 'Yippy', {'length': 0.733}),
('Duckduckgo', 'Yippy', {'length': 0.795}), ('Ecosia', 'Yippy', {'length': 0.793}),
('Google', 'Yippy', {'length': 0.852}), ('Lilo', 'Yippy', {'length': 0.43}),
('Lycos', 'Yippy', {'length': 0.766}), ('Qwant', 'Yippy', {'length': 0.834}),
('Startpage', 'Yippy', {'length': 0.77}), ('Teoma', 'Yippy', {'length': 0.776}),
('Yahoo', 'Yippy', {'length': 0.445})]
G = nx.DiGraph()
G.add_edges_from(edgelist)
plt.figure(figsize=(20,12))
pos = nx.spring_layout(G)
nx.draw_networkx_nodes(G, pos=pos, withlabels=True,
node_size=1200, node_color='lightblue')
nx.draw_networkx_labels(G, pos=pos)
nx.draw_networkx_edges(G, edgelist=edgelist, pos=pos)
nx.draw_networkx_edge_labels(G, pos=pos)
plt.box(False)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.