- line_graph(G, create_using=None)¶
Return the line graph of the graph or digraph G.
The line graph of a graph G has a node for each edge in G and an edge between those nodes if the two edges in G share a common node. For directed graphs, nodes are connected only if they form a directed path of length 2.
The nodes of the line graph are 2-tuples of nodes in the original graph (or 3-tuples for multigraphs, with the key of the edge as the 3rd element).
For more discussion, see the docstring in networkx.generators.line.
G : graph
A NetworkX Graph, DiGraph, MultiGraph, or MultiDigraph.
L : graph
The line graph of G.
Graph, node, and edge data are not propagated to the new graph. For undirected graphs, the nodes in G must be sortable—otherwise, the constructed line graph may not be correct.
>>> G = nx.star_graph(3) >>> L = nx.line_graph(G) >>> print(sorted(L.edges())) # makes a clique, K3 [((0, 1), (0, 2)), ((0, 1), (0, 3)), ((0, 3), (0, 2))]