Reputation: 950
I need to draw a graph with duplicate edges (i.e., more than one edge between 2 nodes). I tried:
import networkx as nx
edges = [(0, 1), (0, 1)]
G = nx.DiGraph ()
G.add_edges_from (edges)
print G.edges ()
#[(0, 1)]
Duplicate entries are simply discarded. Is there any way to do that?
Upvotes: 1
Views: 3473
Reputation: 10841
I'm no expert on networkx
either but, according to the documentation here:
Multigraphs NetworkX provides classes for graphs which allow multiple edges between any pair of nodes. The MultiGraph and MultiDiGraph classes allow you to add the same edge twice, possibly with different edge data. This can be powerful for some applications, but many algorithms are not well defined on such graphs. Shortest path is one example. Where results are well defined, e.g. MultiGraph.degree() we provide the function. Otherwise you should convert to a standard graph in a way that makes the measurement well defined.
Thus, the example should work if one change is made - create G
as follows:
G = nx.MultiGraph()
Upvotes: 6