Skip to content

Instantly share code, notes, and snippets.

@solebox
Created March 15, 2024 10:16
Show Gist options
  • Save solebox/ad049ef0054748eb8207155674fd2f6c to your computer and use it in GitHub Desktop.
Save solebox/ad049ef0054748eb8207155674fd2f6c to your computer and use it in GitHub Desktop.
how to plot grapg with parallel edges and labels
#!/usr/bin/env python3
from pyvis.network import Network
import networkx as nx
G = nx.MultiDiGraph()
G.add_node(1, label='Node 1', group=1)
G.add_node(2, label='Node 2', group=1)
G.add_node(3, label='Node 3', group=2)
G.add_node(4, label='Node 4', group=2)
G.add_node(5, label='Node 5', group=1)
# Add edges
G.add_edges_from([
(1, 2, {'label': 'Edge 1-2', 'weight': 5}),
(2, 1, {'label': 'Edge 2-1', 'weight': 2}),
(1, 3, {'label': 'Edge 1-3', 'weight': 1}),
(2, 4, {'label': 'Edge 2-4', 'weight': 1}),
(3, 5, {'label': 'Edge 3-5', 'weight': 1}),
(4, 5, {'label': 'Edge 4-5', 'weight': 2})
])
nt = Network(notebook=True, directed=True)
nt.from_nx(G)
nt.show_buttons(filter_=['physics'])
nt.show("nx.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment