NetworKit Visualization Tutorial

The vizbridges module provides the widgetFromGraph function, which creates and returns Python widgets for graph visualization. Per default, a graph is plotted in 2D using the Python-package ipycytoscape. If the parameter dimension to 3D, the graph network is plotted in 3D using plotly. For this to work one or both of the packages have to be installed on the machine, where the Jupyter backend is running. The default mode is 2D. There is an optional parameter for node scores or a partition list (e.g. as a result of from centrality or community detection algorithms). If provided the nodes are colored according to their partition membership or score.

Visualize in 2D using Cytoscape

When plotting a graph in 2D with Cytoscape, the internal layouting algorithm from Cytoscape is used. This and the performance of the plugin makes this visualization suitable for graphs with up to around 500 nodes. For larger graphs, it is recommended to use the 3D visualization.

[1]:
import networkit as nk
from networkit import vizbridges

# Read graph
G = nk.readGraph("../input/karate.graph", nk.Format.METIS)
# Initalize and run Betweenness algorithm
btwn = nk.centrality.Betweenness(G)
btwn.run()

# Visualize the karate graph with Betweenness scores
nk.vizbridges.widgetFromGraph(G, nodeScores = btwn.scores())
[1]:
[2]:
# Initalize and run PLM community detection algorithm
plm = nk.community.PLM(G)
plm.run()

# Visualize the karate graph with community detection
nk.vizbridges.widgetFromGraph(G, nodePartition = plm.getPartition())
[2]:

Visualize in 3D using Plotly

When plotting a graph in 3D with Plotly, the Maxent-Stress layouting from networkit.viz.MaxentStress is used. With a moderate to decent client, graph visualizations with up to 50k of nodes are possible. Note: The time it takes for generating the widget scales with the number of nodes.

[3]:
# Read graph
G = nk.readGraph("../input/karate.graph", nk.Format.METIS)
# Initalize and run Betweenness algorithm
btwn = nk.centrality.Betweenness(G)
btwn.run()

# Visualize the karate graph with Betweenness scores
nk.vizbridges.widgetFromGraph(G, dimension = nk.vizbridges.Dimension.Three, nodeScores = btwn.scores())
[3]:
[4]:
# Initalize and run PLM community detection algorithm
plm = nk.community.PLM(G)
plm.run()

# Visualize the power graph with community detection
nk.vizbridges.widgetFromGraph(G, dimension = nk.vizbridges.Dimension.Three, nodePartition = plm.getPartition())
[4]: