0% found this document useful (0 votes)
33 views

Introduction To Network Analysis in Python Chapter1

The document introduces networks and network analysis in Python. It discusses what networks are and examples like social and transportation networks. It also covers network structure, the NetworkX API, different types of graphs, visualizing networks, and the nxviz API.

Uploaded by

syllabi
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)
33 views

Introduction To Network Analysis in Python Chapter1

The document introduces networks and network analysis in Python. It discusses what networks are and examples like social and transportation networks. It also covers network structure, the NetworkX API, different types of graphs, visualizing networks, and the nxviz API.

Uploaded by

syllabi
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
You are on page 1/ 39

Introduction to

Networks
I N T R O D U C T I O N T O N E T W O R K A N A LY S I S I N P Y T H O N

Eric Ma
Data Carpentry instructor and author of
nxviz package
Networks!
Examples:
Social

Transportation

Model relationships between entities

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Networks!
Insights:

Important entities: in uencers in social network

Path nding: most e cient transport path

Clustering: nding communities

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Network Structure

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Network Structure

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Network Structure

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Network Structure

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


NetworkX API Basics
import networkx as nx
G = nx.Graph()
G.add_nodes_from([1, 2, 3])
G.nodes()

[1, 2, 3]

G.add_edge(1, 2)
G.edges()

[(1, 2)]

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


NetworkX API Basics
G.node[1]['label'] = 'blue'
G.nodes(data=True)

[(1, {'label': 'blue'}), (2, {}), (3, {})]

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


NetworkX API Basics
nx.draw(G)
import matplotlib.pyplot as plt
plt.show()

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Let's practice!
I N T R O D U C T I O N T O N E T W O R K A N A LY S I S I N P Y T H O N
Types of graphs
I N T R O D U C T I O N T O N E T W O R K A N A LY S I S I N P Y T H O N

Eric Ma
Data Carpentry instructor and author of
nxviz package
Undirected graphs
Facebook social graph

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Undirected graphs
import networkx as nx
G = nx.Graph()
type(G)

networkx.classes.graph.Graph

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Directed graphs
Directed: Twi er social graph

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Directed graphs
D = nx.DiGraph()
type(D)

networkx.classes.digraph.DiGraph

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Types of graphs
Multi(Di)Graph: Trip records between bike sharing stations

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Multi-edge (Directed) graphs
M = nx.MultiGraph()
type(M)

networkx.classes.multigraph.MultiGraph

MD = nx.MultiDiGraph()
type(MD)

networkx.classes.multidigraph.MultiDiGraph

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Weights on graphs
Edges can contain weights

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Weights on graphs
Edges can contain weights

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Weights on graphs
Edges can contain weights

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Self-loops
Nodes that are connected to themselves

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Let's practice!
I N T R O D U C T I O N T O N E T W O R K A N A LY S I S I N P Y T H O N
Network
visualization
I N T R O D U C T I O N T O N E T W O R K A N A LY S I S I N P Y T H O N

Eric Ma
Data Carpentry instructor and author of
nxviz package
Irrational vs. Rational visualizations

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Visualizing networks
Matrix plots

Arc plots

Circos plots

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Visualizing networks
Matrix plots

Arc plots

Circos plots

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Matrix plot

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Matrix plot

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Matrix plot

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Matrix plot

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Directed matrices

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Visualizing networks
Matrix Plots

Arc Plots

Circos Plots

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Arc plot

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Visualizing networks
Matrix Plots

Arc Plots

Circos Plots

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Circos plot

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Circos plot

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


nxviz API
import nxviz as nv
import matplotlib.pyplot as plt
ap = nv.ArcPlot(G)
ap.draw()
plt.show()

INTRODUCTION TO NETWORK ANALYSIS IN PYTHON


Let's practice!
I N T R O D U C T I O N T O N E T W O R K A N A LY S I S I N P Y T H O N

You might also like