Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

Functions

Functional interface to graph methods and assorted utilities.

Graph

degree(G[, nbunch, weight]) Return a degree view of single node or of nbunch of nodes.
degree_histogram(G) Return a list of the frequency of each degree value.
density(G) Return the density of a graph.
info(G[, n]) Print short summary of information for the graph G or the node n.
create_empty_copy(G[, with_data]) Return a copy of the graph G with all of the edges removed.
is_directed(G) Return True if graph is directed.
to_directed(graph) Return a directed view of the graph graph.
to_undirected(graph) Return an undirected view of the graph graph.
is_empty(G) Returns True if G has no edges.
add_star(G_to_add_to, nodes_for_star, **attr) Add a star to Graph G_to_add_to.
add_path(G_to_add_to, nodes_for_path, **attr) Add a path to the Graph G_to_add_to.
add_cycle(G_to_add_to, nodes_for_cycle, **attr) Add a cycle to the Graph G_to_add_to.
subgraph(G, nbunch) Return the subgraph induced on nodes in nbunch.
induced_subgraph(G, nbunch) Return a SubGraph view of G showing only nodes in nbunch.
restricted_view(G, nodes, edges) Returns a view of G with hidden nodes and edges.
reverse_view(digraph) Provide a reverse view of the digraph with edges reversed.
edge_subgraph(G, edges) Returns a view of the subgraph induced by the specified edges.

Nodes

nodes(G) Return an iterator over the graph nodes.
number_of_nodes(G) Return the number of nodes in the graph.
neighbors(G, n) Return a list of nodes connected to node n.
all_neighbors(graph, node) Returns all of the neighbors of a node in the graph.
non_neighbors(graph, node) Returns the non-neighbors of the node in the graph.
common_neighbors(G, u, v) Return the common neighbors of two nodes in a graph.

Edges

edges(G[, nbunch]) Return an edge view of edges incident to nodes in nbunch.
number_of_edges(G) Return the number of edges in the graph.
density(G) Return the density of a graph.
non_edges(graph) Returns the non-existent edges in the graph.

Self loops

selfloop_edges(G[, data, keys, default]) Returns an iterator over selfloop edges.
number_of_selfloops(G) Return the number of selfloop edges.
nodes_with_selfloops(G) Returns an iterator over nodes with self loops.

Attributes

is_weighted(G[, edge, weight]) Returns True if G has weighted edges.
is_negatively_weighted(G[, edge, weight]) Returns True if G has negatively weighted edges.
set_node_attributes(G, values[, name]) Sets node attributes from a given value or dictionary of values.
get_node_attributes(G, name) Get node attributes from graph
set_edge_attributes(G, values[, name]) Sets edge attributes from a given value or dictionary of values.
get_edge_attributes(G, name) Get edge attributes from graph

Freezing graph structure

freeze(G) Modify graph to prevent further change by adding or removing nodes or edges.
is_frozen(G) Return True if graph is frozen.