1

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?

3

1 Answer 1

6

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.