1

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

Johannes Wiesner
  • 1,006
  • 12
  • 33

1 Answers1

2

What version are you using? I just tried running your code:

import networkx as nx
from pyvis.network import Network

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

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

and I obtain the result you are looking for:

two nodes with arc edges

You can find the output HTML here: https://pastecode.io/s/anav9333

I am using version pyvis=0.3.0

Mehdi Saffar
  • 691
  • 1
  • 8
  • 24
  • 1
    Ha! You're right! Unfortunately, I have a new machine now and can't remember which version I used on the old one. Besides, the old machine was running Windows (don't know if this might have an effect on the layout?) – Johannes Wiesner Oct 05 '22 at 16:29
  • It is probably due to an older version. I don't think the operating system has any impact on the result, given that it is Javascript running on the browser's engine. If my answer helped you, feel free to mark it as accepted answer :) – Mehdi Saffar Oct 05 '22 at 17:53