0

I want to display the information in the following example dataset as a directed graph with multiple edges between nodes.

Attached is an example of the kind of graph I expect, as well as my code, which does not produce the expected output.

Thanks,

G = nx.from_pandas_edgelist(df, 'source', 'destination', edge_attr='number of passengers', create_using=nx.DiGraph())
pos = nx.random_layout(G)
nx.draw(G, 
        pos=pos)
edge_labels = nx.get_edge_attributes(G, "Edge_label")
nx.draw(G, with_labels=True)
nx.draw_networkx_edge_labels(G, pos, edge_labels)

plt.show()

enter image description here

date source destination number of passengers
2019-01-01 NY BERLIN 10
2019-01-02 NY PARIS 50
2019-01-03 NY BERLIN 40
2019-01-04 BERLIN PARIS 20
2019-01-05 NY PARIS 15
2019-01-06 BERLIN NY 17
Peter Leimbigler
  • 10,775
  • 1
  • 23
  • 37
MAK
  • 605
  • 9
  • 19
  • 2
    Have a look at https://networkx.org/documentation/stable/reference/classes/multidigraph.html and https://stackoverflow.com/questions/14943439/how-to-draw-multigraph-in-networkx-using-matplotlib-or-graphviz – Peter Leimbigler Sep 27 '21 at 04:00
  • @PeterLeimbigler this answer is not give solution to my problem , it's not deal with multiple direct graph that one node have two or more edges to other node , and plot the label for each edge . maybe you find something I miss ... – MAK Oct 05 '21 at 13:58
  • The networkx link is for MultiDiGraph, which is "a directed graph class that can store multiedges. Multiedges are multiple edges between two nodes." As far as I can see, that's exactly what you're looking for: "a directed graph with multiple edges between nodes." The StackOverflow link I provided is an old but still helpful guide to actually display multiple edges in matplotlib. – Peter Leimbigler Oct 05 '21 at 14:46

0 Answers0