A list of graphs that can be created with NetworkX.
The version of NetworkX is 2.4. This is a Japanese translation of the Official Documentation. Not all are covered. Please let us know if the translation is incorrect.
Please import networkx
and matplotlib.pyplot
in advance to execute the code below.
import networkx as nx
import matplotlib.pyplot as plt
balanced_tree(r, h, create_using=None)
Returns a perfectly balanced r
branch tree with a height of h
.
Parameters | Type | Description |
---|---|---|
r | int | The number of branches of the tree. Each node has r child nodes. |
h | int | Tree height |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
#balanced_tree
G=nx.balanced_tree(3,2)
plt.cla()
nx.draw_networkx(G)
plt.show()
barbell_graph(m1, m2, create_using=None)
Returns a barbell graph (a graph in which two complete graphs consisting of m1
nodes are connected by a single path consisting of m2
nodes).
Parameters | Type | Description |
---|---|---|
m1 | int | Left and right complete graph(bell)Number of. m1>1 |
m2 | int | The number of nodes on the route connecting the left and right complete graphs. m2>=0 |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Node numbering method
Complete graph on the left: 0,1, ..., m1-1
Route: m1, m1 + 1, ..., m1 + m2-1
Complete graph on the right: m1 + m2, m1 + m2 + 1, ..., 2 * m1 + m2-1
Example 1
#barbell_graph
G=nx.barbell_graph(5,2)
plt.cla()
nx.draw_networkx(G)
plt.show()
Example 2 (when m2 = 0)
G=nx.barbell_graph(5,0)
plt.cla()
nx.draw_networkx(G)
plt.show()
binomial_tree(n)
Returns a binary tree of degree n
. The number of nodes is $ 2 ^ n $ and the number of edges is $ 2 ^ n-1 $.
Parameters | Type | Description |
---|---|---|
n | int | Degree of tree |
Example
G=nx.binomial_tree(3)
plt.cla()
nx.draw_networkx(G)
plt.show()
complete_graph(n, create_using=None)
Returns a graph in which one node is bound to all other nodes.
Parameters | Type | Description |
---|---|---|
n | int or iterable container of nodes | When n is an integer type, the node is range(n)It is created from. When n is an iterable container for nodes, graphs are created with those nodes |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example 1 (when n is an integer type)
G=nx.complete_graph(6)
plt.cla()
nx.draw_networkx(G)
plt.show()
Example 2 (when n is a container for nodes)
G=nx.complete_graph(range(12,18))
plt.cla()
nx.draw_networkx(G)
plt.show()
complete_multipartite_graph(*subset_sizes)
Parameters | Type | Description |
---|---|---|
subset_sizes | taple of integers or tuple of node iterables | When n is an integer, each subset of the multipartite graph has n vertices. When n is iterable, a graph will be created with those nodes |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example Create a complete multipartite graph consisting of three subsets, each with a few nodes.
G=nx.complete_multipartite_graph(2,3,3)
plt.cla()
nx.draw_networkx(G)
plt.show()
circular_ladder_graph(n, create_using=None)
Returns a circular ladder graph of length n.
Parameters | Type | Description |
---|---|---|
n | int | Length of one lap |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.circular_ladder_graph(10)
plt.cla()
nx.draw_networkx(G)
plt.show()
circulant_graph(n, offsets, create_using=None)
Returns a circular graph consisting of n
nodes. Which node a node connects to is specified by ʻoffsets`.
Parameters | Type | Description |
---|---|---|
n | int | Number of nodes |
offsets | lists of integers | List of node offsets |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.circulant_graph(10,[1,2])
plt.cla()
nx.draw_networkx(G)
plt.show()
Since ʻoffsets = [1,2]`, the vertices i are connected to the vertices i + 1 and i + 2, respectively. Vertex 0 is connected to vertices 1 and 2, vertex 1 is connected to vertices 2 and 3, ..., and vertex 9 is connected to vertices 0 and 1.
cycle_graph(n, create_using=None)
Parameters | Type | Description |
---|---|---|
n | int or iterble container of nodes | When n is an integer type, the node is range(n)It is created from. When n is an iterable container for nodes, graphs are created with those nodes |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.cycle_graph(10)
plt.cla()
nx.draw_networkx(G)
plt.show()
dorogovtsev_goltsev_mendes_graph(n, create_using=None)
Returns the graph created by the Dorogovstev-Goltsev-Mendes algorithm.
Original paper https://arxiv.org/abs/cond-mat/0112143
Parameters | Type | Description |
---|---|---|
n | int | Number of generations |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
G=nx.dorogovtsev_goltsev_mendes_graph(3)
plt.cla()
nx.draw_networkx(G)
plt.show()
empty_graph(n=0, create_using=None, default=<class 'networkx.classes.graph.Graph'>)
Returns a graph of n
nodes with no edges.
Parameters | Type | Description |
---|---|---|
n | int | Number of nodes |
create_using | Graph Instance, Constructor or None | The type of graph you want to create. When None is specifieddefault Use the constructor. |
default | Graph constructor (optional, default = nx.Graph) | create_using=None Constructor used when. |
Example
G=nx.empty_graph(10)
plt.cla()
nx.draw_networkx(G,pos)
plt.show()
The variable create_using must be a Graph constructor or a "graph" -like object.
There are three main uses for create_using.
Create an empty directed graph (DiGraph).
n = 10
G = nx.empty_graph(n, create_using=nx.DiGraph)
Creates an empty graph G2 with edges removed from the complete graph G1.
n=5
G1=nx.complete_graph(n)
G1.number_of_edges() #10
G2=nx.empty_graph(n,create_using=G1)
G2.number_of_edges() #0
For your own graph creation function mygraph
, set to use the default constructor nx.MultiGraph
if create_using
is not specified, and to use the specified constructor otherwise.
def mygraph(n, create_using=None):
G = nx.empty_graph(n, create_using, default=nx.MultiGraph)
G.add_edges_from([(0, 1), (0, 1)])
return G
G = mygraph(3)
G.is_multigraph() #True
G = mygraph(3, nx.Graph)
G.is_multigraph() #False
full_rary_tree(r, n, create_using=None)
Creates all r
branches consisting of n
nodes. Every node is a leaf or has r
child nodes.
Parameters | Type | Description |
---|---|---|
r | int | Number of branches in the tree |
n | int | Number of nodes |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.full_rary_tree(3,16)
pos=nx.spring_layout(G,iterations=1000)
plt.cla()
nx.draw_networkx(G,pos)
plt.show()
ladder_graph(n, create_using=None)
Returns a ladder graph.
Parameters | Type | Description |
---|---|---|
n | int | Ladder length |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.ladder_graph(7)
plt.cla()
nx.draw_networkx(G)
plt.show()
lollipop_graph(m, n, create_using=None)
Returns a lollipop graph (a complete graph of m
nodes and a path of n
nodes connected to it).
Parameters | Type | Description |
---|---|---|
m | int or iterable container of nodes (default = 0) | Number of nodes that make up a complete graph |
n | int or iterable container of nodes (default = 0)) | Number of nodes that make up the route |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.lollipop_graph(6,3)
plt.cla()
nx.draw_networkx(G)
plt.show()
null_graph(create_using=None)
Returns a graph with no nodes or edges.
See ʻempty_graph for how to use
create_using`.
Parameters | Type | Description |
---|---|---|
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.null_graph()
plt.cla()
nx.draw_networkx(G)
plt.show()
path_graph(n, create_using=None)
Returns a graph of n
nodes that does not pass through the same node twice.
Parameters | Type | Description |
---|---|---|
n | int or iterable | Number of nodes |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
G=nx.path_graph(5)
plt.cla()
nx.draw_networkx(G)
plt.show()
star_graph(n, create_using=None)
Returns a graph with n
outer nodes concatenated for one central node.
Parameters | Type | Description |
---|---|---|
n | int or iterable | Number of outer peripheral nodes |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
G=nx.star_graph(5)
plt.cla()
nx.draw_networkx(G)
plt.show()
trivial_graph(create_using=None)
Returns the simplest graph consisting of only one node.
Parameters | Type | Description |
---|---|---|
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
G=nx.trivial_graph()
plt.cla()
nx.draw_networkx(G)
plt.show()
turan_graph(n, r)
Returns a complete multipartite graph with n
nodes divided into r
unconnected parts.
The number of edges is the number rounded down to the fraction of n ** 2 * (r-1) / (2 * r)
.
Parameters | Type | Description |
---|---|---|
n | int | The number of nodes. |
r | int | Number of unconnected parts. 1<=r<=Must be n. |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
G=nx.turan_graph(6,3)
plt.cla()
nx.draw_networkx(G)
plt.show()
The node is divided into three parts (0,1), (2,3), (4,5). Nodes that belong to the same part are not concatenated.
The graph given in the example says, "Three couples went to a cocktail party. At the venue, everyone shook hands with all the participants except themselves and their spouse. The relationship at that time was noded to the participants. , What kind of graph would you get if you express your handshake as an edge? ”Is the answer to the question. Therefore, it is called "Cocktail Party Graph".
wheel_graph(n, create_using=None)
Returns a graph with n-1 perimeter nodes concatenated for a hub node.
Parameters | Type | Description |
---|---|---|
n | int or iterable | The number of nodes. |
create_using | NetworkX graph constructor, optional (default=nx.Graph) | The type of graph you want to create |
Example
G=nx.wheel_graph(10)
plt.cla()
nx.draw_networkx(G)
plt.show()
It is a sparse graph with a strongly connected component.
margulis_gabber_galil_graph(n, create_using=None)
Returns a Margulis-Gabber-Galil graph. It is an undirected multiplex graph with a node degree of 8. The second largest eigenvalue of the adjacency matrix in this graph is $ 5 \ sqrt {2} $. An error is returned if the graph is not directed or multiple graphs.
Parameters | Type | Description |
---|---|---|
n | int or iterable | Defines the number of nodes. The number of nodes is |
create_using | NetworkX graph constructor, optional (default MultiGraph) | The type of graph you want to create |
G=nx.margulis_gabber_galil_graph(3)
pos=nx.circular_layout(G)
plt.cla()
nx.draw_networkx(G)
plt.show()
chordal_cycle_graph(p, create_using=None)
Returns a cycle graph with chords (edges that are not part of the cycle but connect between two nodes on the cycle graph). Node x has a string for node y that satisfies x * y = 1 (mod p). An error is returned if the graph is not directed or multiple graphs.
Parameters | Type | Description |
---|---|---|
p | prime number | Defines the number of nodes. Must be a prime number. |
create_using | NetworkX graph constructor, optional (default MultiGraph) | The type of graph you want to create |
G=nx.chordal_cycle_graph(7)
pos=nx.circular_layout(G)
plt.cla()
nx.draw_networkx(G,pos)
plt.show()
Social Networks
The famous social network graph.
karate_club_graph()
A network of members of the karate club surveyed by American social psychologist Zachary. You can see that it is divided into two factions centered on node 0 and nodes 32 and 33.
Zachary, Wayne W. “An Information Flow Model for Conflict and Fission in Small Groups.” Journal of Anthropological Research, 33, 452–473, (1977).
G=nx.karate_club_graph()
plt.figure(figsize=(8,6))
nx.draw_networkx(G)
plt.show()
davis_southern_women_graph()
A network of 18 women in the southern United States surveyed by Davis et al. In the 1930s. This is a bipartite graph consisting of nodes representing 18 women and 14 participating events.
A. Davis, Gardner, B. B., Gardner, M. R., 1941. Deep South. University of Chicago Press, Chicago, IL.
florentine_families_graph()
It is the marriage relationship of influential families such as the Medici family in Renaissance Florence.
Ronald L. Breiger and Philippa E. Pattison Cumulated social roles: The duality of persons and their algebras,1 Social Networks, Volume 8, Issue 3, September 1986, Pages 215-256
les_miserables_graph()
les_miserables_graph()
It is a graph of the characters in the novel "Les Miserables".
D. E. Knuth, 1993. The Stanford GraphBase: a platform for combinatorial computing, pp. 74-87. New York: AcM Press.