Installation and use of Networkx under Ubuntu

Source: Internet
Author: User

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

   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.