Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Six layouts of the same hypergraph#
The HAT-VIS similarity layout places similar vertices close to each other; the HyperGodot force-directed layout balances centroid springs and repulsion; the membership-aware layout of hatvis keeps the similarity geometry but pushes non-members out of hyperedge discs; the circular, spectral and bipartite layouts are classical alternatives. The layout quality table reports the stress against the similarity distances and the number of intrusions (non-members inside a hull).
import matplotlib.pyplot as plt
import pandas as pd
import hatvis as hv
from hatvis.plotting import draw_hypergraph, resolve_layout
H = hv.datasets.load_manufacturing_cps()
names = ["similarity", "force", "membership", "circular", "spectral", "bipartite"]
# [snippet:layouts]
layouts = {name: resolve_layout(H, None, name, random_state=0) for name in names}
quality = pd.DataFrame({name: hv.layout_quality(H, pos) for name, pos in layouts.items()}).T
print(quality.round(3))
# [/snippet:layouts]
stress intrusions hyperedges with intrusions mean hull area
similarity 0.080 2.0 2.0 0.034
force 0.126 1.0 1.0 0.091
membership 0.051 0.0 0.0 0.049
circular 0.084 0.0 0.0 0.089
spectral 0.100 6.0 5.0 0.037
bipartite 0.137 0.0 0.0 0.026
fig, axes = plt.subplots(2, 3, figsize=(15, 9.5))
for ax, (name, pos) in zip(axes.ravel(), layouts.items(), strict=False):
draw_hypergraph(H, pos=pos, ax=ax, legend=False, title=f"{name} (intrusions: {int(quality.loc[name, 'intrusions'])})")
plt.tight_layout()

Total running time of the script: (0 minutes 0.808 seconds)