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
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)
Dostları ilə paylaş: