Plotting multi-edge directed graphs using pyvis in a way that shows all edges separately

Viewed 36

Note: This post is directly related to this one, except that I am looking for a solution in pyvis.

I would like to plot a directed graph with multiedges, that is, each pair of nodes is connected with two edges in opposite directions. In order to that, it is important, that the two edges do not overlap visually. When using networkx.draw() this problem can be solved by passing connectionstyle='arc3, rad = 0.1' to nx.draw() as described here. However, I am using for a solution in pyvis.

Example using networkx.draw():

import networkx
from pyvis.network import Network

# create a graph
G = nx.MultiDiGraph()
G.add_edges_from([
    (1, 2),
    (2, 3),
    (3, 2),
    (2, 1),
])


# draw with networkx using the proposed solution
nx.draw(G, connectionstyle='arc3, rad = 0.1')

enter image description here

# This is how the graph currently looks with pyvis
nt = Network('500px', '500px',directed=True)
nt.from_nx(G)
nt.show('nx.html')

enter image description here

0 Answers
Related