Visualizing networks
A common first step in analyzing a network is to draw the network, which can help us identify some of the prominent features of a network. (Of course, drawings can be misleading, so we should not rely on them too heavily in our analysis.)
In this recipe, we’ll describe how to use the network drawing facilities in the NetworkX package to visualize a network.
Getting ready
For this recipe, we will need to import the NetworkX package under the nx
alias, as described in the Technical requirements section. We will also need the Matplotlib package. For this, as usual, we must import the pyplot
module as plt
using the following import
statement:
import matplotlib.pyplot as plt
How to do it...
The following steps outline how to draw a simple network object using the drawing routines from NetworkX:
- First, we will create a simple example network to draw:
G = nx.Graph()
G.add_nodes_from(range(1, 7))
G.add_edges_from([
...