0% found this document useful (0 votes)
135 views38 pages

PDF Networkx

NetworkX is a Python package designed for creating, manipulating, and analyzing complex networks, offering features such as data structures for various types of graphs, standard algorithms, and the ability to hold arbitrary data in edges. Users need to install Python and the package via pip, along with matplotlib for graph plotting. The document includes examples of graph creation, operations, and commands for various graph analyses.

Uploaded by

Sameer Rachcha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views38 pages

PDF Networkx

NetworkX is a Python package designed for creating, manipulating, and analyzing complex networks, offering features such as data structures for various types of graphs, standard algorithms, and the ability to hold arbitrary data in edges. Users need to install Python and the package via pip, along with matplotlib for graph plotting. The document includes examples of graph creation, operations, and commands for various graph analyses.

Uploaded by

Sameer Rachcha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Ratnavali N.

Tilak
1
NetworkX is a Python package for
the creation, manipulation, and
study of the structure, dynamics,
and functions of complex networks.

2
Features of NetworkX :
• Data structures for graphs, digraphs, and
multigraphs
• Many standard graph algorithms
• Network structure and analysis measures
• Generators for classic graphs, random graphs,
and synthetic networks
• Nodes can be "anything" (e.g., text, images,
XML records)
3
Features of NetworkX : continued

• Edges can hold arbitrary data (e.g., weights,


time-series)
• Open source
• NetworkX provides basic functionality for
visualizing graphs, but its main goal is to enable
graph analysis rather than perform graph
visualization.

4
 Before using this package we need to
download it. Python must be already installed.
 Then install using pip install on command
prompt.
 Installing of package matplotlib is needed
with it to plot the graphs.
5
Creating a simple undirected graph and
plotting it using NetworkX on IDLE shell :

6
Creating a graph with only edgeset is also possible
vertices are generated accordingly.

7
Creating a graph and adding single node and/or edge

8
Program Creating a graph with vertex labels, colors etc:

9
10
Program for finding number of vertices ,edges, vertex set :

Program outputs 

11
Program output 1 

Program output 2 (after closing graph window )

12
Program for generating a multigraph:

13
Program for generating a directed graph:

Program outputs 
14
15
Underlying graph of directed graph

16
Finding adjacency_matrix and incidence_matrix of a graph:
graph:

17
Using a graph represented by an adjacency_matrix
declared as numpy array:

18
Python Code for Different types of graphs: outputs

19
Python Codes for Different types of graphs: outputs

20
Python Codes for Different types of graphs: outputs

21
Verifying whether graphs are isomorphic:

22
Few more important commands to check whether a graph
is directed, connected, bipartite, regular etc.

23
Graph operations 1: Intersection of graphs

24
Output graphs :

g1 g2

Intersection

25
Graph operations 2: Union of graphs
There are 2 types of unions. Usual union is obtained
by command compose and other is disjoint union of
graphs. Union with rename also gives disjoint union.

26
Output nx.compose(g1,g2)

27
nx.disjoint_union(g1,g2)

nx.union(g1,g2,rename=("g1", "g2"))

28
Graph operations 3: Product of graphs
Three types of Products of Graphs are :

29
Using networkx all the three product are possible.
The commands are cartesian_product(),
tensor_product
strong_product()
30
Product of Graphs

31
Two graphs and their products

tensor_product
cartesian_product strong_product
32
Operation of deletion of vertices :

33
deletion of vertices a and b from graph g:

g G - {a, b}

34
Operation of deletion of edges :

35
deletion of vertices a and b from graph g:

g G - {(2,3),("b","a")}

36
Subgraph: The vertex induced subgraph can be obtained
using subgraph command in networkx.

37
That's all for now.

Any questions?

38

You might also like