The-Python-Graph-Gallery icon indicating copy to clipboard operation
The-Python-Graph-Gallery copied to clipboard

No More Sadness and Despair for Hierarchical Edge Bundling with Python.

Open paulbrodersen opened this issue 3 years ago • 2 comments

If you're aware of any tip to build it, please let me knwo!

I built and maintain a python library for network visualisation called netgraph. Netgraph accepts igraph and networkx Graph objects as input (as well as many other sensible data structures to represent graphs in python).

For edge bundling, netgraph implements the FDEB algorithm proposed by Holten & Wijk (2009).

Example visualization that combines a modular node layout with edge bundling:

import matplotlib.pyplot as plt
import networkx as nx

from netgraph import Graph # pip install netgraph

# create a modular graph
partition_sizes = [10, 20, 30, 40]
g = nx.random_partition_graph(partition_sizes, 0.5, 0.1)

# position nodes according to their community using the `community` node layout
node_to_community = dict()
node = 0
for community_id, size in enumerate(partition_sizes):
    for _ in range(size):
        node_to_community[node] = community_id
        node += 1

# color nodes according to their community
community_to_color = {
    0 : 'tab:blue',
    1 : 'tab:orange',
    2 : 'tab:green',
    3 : 'tab:red',
}
node_color = {node: community_to_color[community_id] for node, community_id in node_to_community.items()}

Graph(g,
      node_color=node_color, node_edge_width=0, edge_alpha=0.1,
      node_layout='community', node_layout_kwargs=dict(node_to_community=node_to_community),
      edge_layout='bundled', edge_layout_kwargs=dict(k=2000),
)

plt.show()

community_layout

paulbrodersen avatar Feb 03 '22 11:02 paulbrodersen

This is very very cool, thanks for your message!! I definitely have to add it to the website.

I don't have the bandwidth right now to do so, but it will happen for sure.

Would you be interested in writing a jupyter notebook that describes this feature more in depth and make a PR? It could help promote your work!

Thanks again for reaching out.

holtzy avatar Feb 15 '22 09:02 holtzy

Sure, can do. Apart from the code example above, what else would you like to see in the notebook?

paulbrodersen avatar Feb 15 '22 09:02 paulbrodersen