Http://networkx.github.io/documentation/networkx-1.9/install.html
1. Installing Setuptools
wget Https://bootstrap.pypa.io/ez_setup.py-O-| sudo python
2. Installing NETWORKX
Pip Install Networkx (install under root privileges, otherwise error, but I have some warning message during installation)
3. Install NumPy and matplotlib (Support Networkx Drawing)
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy Python-nose
4. Using Networkx
4.1 New graph.py (any name)
ImportNetworkx as NXImportMatplotlib.pyplot as Pltdefdraw_graph (graph):#extract nodes from graphnodes = Set ([N1 forN1, N2inchGraph] + [n2 forN1, N2inchGraph]) #Create Networkx Graphg=NX. Graph ()#Add Nodes forNodeinchnodes:g.add_node (node)#Add Edges forEdgeinchGraph:g.add_edge (edge[0], edge[1]) #Draw Graphpos =Nx.shell_layout (g) Nx.draw (g, POS)#Show Graphplt.show ()#Draw ExampleGraph = [(20, 21), (21, 22), (22, 23), (23, 24), (24, 25), (25, 20))]draw_graph (graph)
4.2 Executive graph.py
sudo python graph.py