networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
complete_multipartite_graph(*subset_sizes)

Notes

This function generalizes several other graph builder functions.

Parameters

subset_sizes : tuple of integers or tuple of node iterables

The arguments can either all be integer number of nodes or they can all be iterables of nodes. If integers, they represent the number of nodes in each subset of the multipartite graph. If iterables, each is used to create the nodes for that subset. The length of subset_sizes is the number of subsets.

Returns

G : NetworkX Graph

Returns the complete multipartite graph with the specified subsets.

For each node, the node attribute 'subset' is an integer indicating which subset contains the node.

Returns the complete multipartite graph with the specified subset sizes.

See Also

complete_bipartite_graph

Examples

Creating a complete tripartite graph, with subsets of one, two, and three nodes, respectively.

>>> G = nx.complete_multipartite_graph(1, 2, 3)
>>> [G.nodes[u]["subset"] for u in G]
[0, 1, 1, 2, 2, 2]
>>> list(G.edges(0))
[(0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]
>>> list(G.edges(2))
[(2, 0), (2, 3), (2, 4), (2, 5)]
>>> list(G.edges(4))
[(4, 0), (4, 1), (4, 2)]
>>> G = nx.complete_multipartite_graph("a", "bc", "def")
>>> [G.nodes[u]["subset"] for u in sorted(G)]
[0, 1, 1, 2, 2, 2]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.drawing.layout.multipartite_layout

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/generators/classic.py#700
type: <class 'function'>
Commit: