0

It's about search engines (SE). I'm trying to represent distances between one SE and the others with graphs. I labelled them:

DG.add_edge(se1, se2, length=distance[se1][se2])

Then to label the edges

nx.draw_networkx_edge_labels(DG, pos=pos, font_size=8) but outputs are quite incoherents :

enter image description here

Sample

[('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})] 
Lamanus
  • 12,898
  • 4
  • 21
  • 47
gwen_m
  • 1
  • Can you share a sample of `DG.edges(data=True)` so we can reproduce? – yatu Jul 28 '20 at 12:53
  • 1
    [('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})] – gwen_m Jul 28 '20 at 13:03

1 Answers1

0

Not sure which step of yours is causing the error. Make sure to specify an edgelist when drawing the graph, just in case. This could cause discrepancies for older versions otherwise. The following seems to produce as expected:

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)

enter image description here

yatu
  • 86,083
  • 12
  • 84
  • 139
  • I have quite the same result as you. The problem for exaple is that the edge {'AOL', 'Yippy'} is longer than the edge {'Teoma', 'Yippy'} while there respective length should be 0.446 and 0.776... The theoritical lengths and the real length are not proportional, thus the vizualisation don't really have sense.. – gwen_m Jul 29 '20 at 08:39
  • You can't modify the lengths directly using an edge attribute @gwen_m You could modify the widths of the edges (see https://stackoverflow.com/a/62139935/9698684 ) but not the edge length. You'd have to set the corresponding coordinates, which are given by the used layout – yatu Jul 29 '20 at 10:54
  • Hmmhmm ok I see, too bad that it dosn't work like this. Thank you very much for your help – gwen_m Jul 30 '20 at 07:55