Getting started: drawing graphs
• NetworkX is not primarily a graph drawing package but it provides basic drawing
capabilities by using matplotlib. For more complex visualization techniques it
provides an interface to use the open source GraphViz software package.
>>> import pylab as plt #import Matplotlib plotting interface >>> g = nx.watts_strogatz_graph(100, 8, 0.1) >>> nx.draw(g) >>> nx.draw_random(g) >>> nx.draw_circular(g) >>> nx.draw_spectral(g) >>> plt.savefig('graph.png') 25
3. Basic network analysis
26
Basic analysis: the Cambridge place network
27
A directed network with integer
ids as nodes
Two places (nodes) are
connected if a user transition has
been observed between them
Visualization thanks to Java unfolding:
http://processing.org/
http://unfoldingmaps.org/
Basic analysis: graph properties
• Find the number of nodes and edges, the average degree and the number of
connected components
cam_net = nx.read_edgelist('cambridge_net.txt', create_using=nx.DiGraph(), nodetype=int)