This demonstrates an implementation of spectral drawing. Here, the lower eigenvectors of the Laplacian are being used. Since these eigenvectors tend to be comparatively stable between "neighboring" vertices, the entries can directly (with some normalization) be used as x- and y-coordinates.
Additionally, the coordinates are dampened by their respective eigenvalues. See for example here for details.
from networkit import *
%matplotlib inline
import matplotlib.pyplot as plt
First, we lay out a generated power-law network (try different generators!):
G = networkit.generators.BarabasiAlbertGenerator(3, 100, 10).generate()
#G = NetworKit.generators.RmatGenerator(7, 5, 0.34, 0.23, 0.23, 0.2).generate()
layout = networkit.viztools.layout.SpectralLayout()
networkit.viztasks.drawGraph(G, layout=layout)
As you could see (try the RMAT generator with the provided values a couple of times!), power-law networks are not well suited for spectral drawing. This is not surprising, since these networks have vertices with an outstanding eigenvector centrality, leading to vertex placement leaning towards extreme values.
Luckily, the repository of example graphs contains some mesh networks. Note that I scaled down the node sizes. Have a look (takes some time):
G = readGraph("/home/cobalt/iPython/NetworKit/input/airfoil1.graph", Format.METIS)
layout = networkit.viztools.layout.SpectralLayout()
networkit.viztasks.drawGraph(G, layout=layout, figsize=(15,15), nodeSizes = [0.2]*G.numberOfNodes())
Another very nice one (more vertices - takes even more time):
G = readGraph("/home/cobalt/iPython/NetworKit/input/wing.graph", Format.METIS)
layout = networkit.viztools.layout.SpectralLayout()
networkit.viztasks.drawGraph(G, layout=layout, figsize=(25,25), nodeSizes = [0.03]*G.numberOfNodes())
And because it's so nice, have another one:
G = readGraph("/home/cobalt/iPython/NetworKit/input/4elt.graph", Format.METIS)
layout = networkit.viztools.layout.SpectralLayout()
networkit.viztasks.drawGraph(G, layout=layout, figsize=(20,20), nodeSizes = [0.03]*G.numberOfNodes())
G = readGraph("/home/cobalt/iPython/NetworKit/input/fe_4elt2.graph", Format.METIS)
layout = networkit.viztools.layout.SpectralLayout()
networkit.viztasks.drawGraph(G, layout=layout, figsize=(20,20), nodeSizes = [0.03]*G.numberOfNodes())
G = networkit.graph.Graph(10000)
vertices = {}
for i in range(0, 100):
for j in range(0,100):
# Top
if j > 0:
G.addEdge((i * 100 + j), (i * 100 + j - 1))
# left
if i > 0:
G.addEdge((i * 100 + j), ((i - 1) * 100 + j))
layout = networkit.viztools.layout.SpectralLayout()
networkit.viztasks.drawGraph(G, layout=layout, figsize=(20,20), nodeSizes = [0.01]*G.numberOfNodes())