So far in this series, we’ve gone through everything from creating a graph to analysing it. We have yet to visualise networks. To conclude this series, this blog post sets out to walk through the process of visualising networks using tools packaged into networkx
Before we draw the graph, we need to define a layout. A layout is used to determine how nodes and edges are positioned on the canvas. There are many different types of layouts to use depending on your network structure. A selection of these layouts are listed as follows:
- Spring layout : One of the most popular layout algorithms which uses a force-directed layout. Edges act as springs by pulling nodes together.
- Bipartite layout: Used to position nodes into two groups. The two sets of nodes are positioned into two straight lines. Requires a set of nodes to partition to one side.
- Circular layout : Positions nodes into a circular formation.
- Spectral layout : Used to position highly clustered nodes together.
Other honourable mentions include…
- Kamada-Kawai layout :
- Planar layout :
- Random layout :
- Shell layout :
Now that we selected our layout, we can begin to draw the networks. Drawing networks using networkx is done in two parts. Both nodes and edges are drawn separately. This is done so that the analyst has complete control over how the network is presented.
Here’s a quick example to get things going. To begin, we can draw our nodes using two parameters: The graph
G and the layout configuration we defined earlier
>>> nx.draw_networkx_nodes(G, pos)
A complete set of customisable parameters can be found here .
Drawing the edges can be done in a similar fashion. This also takes the graph
G and the layout
pos . Likewise, a complete set of customisable parameters can be found here .
>>> nx.draw_networkx_edges(G, pos)
Now that we’ve got everything we need, you can put it all together and make some pretty Now that we’ve got everything we need, you can put it all together and make some pretty impressive data visualisations. This brief blog post provides the very basic tools need to get started.
As you can imagine, there is far more to network visualisations than just this. I made this blog post as small as possible with just enough material to get things started. There is so much more that could have been added but would have required a whole series of blog posts just to scratch the surface.