Construct a Simple Network with NetworkX

A NetworkX project begins with importing module networkx (usually under the name nx).

 import​ ​networkx​ ​as​ ​nx

Create a Graph

A NetworkX network is a collection of edges and labeled nodes. The library allows you to use any hashable Python data as a node label (different labels within the same graph may belong to different data types). To create a new network graph, you must choose an appropriate graph type and call the respective constructor; pass either no parameters (for an empty graph) or a list of edges as node pairs (lists or tuples). NetworkX supports four graph types:

  • Undirected graphs consist only of undirected edges—edges that can be traversed in either direction so that an edge from ...

Get Complex Network Analysis in Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.