bipartite_layout#
- bipartite_layout(G, nodes, align='vertical', scale=1, center=None, aspect_ratio=1.3333333333333333, store_pos_as=None)[source]#
Position nodes in two straight lines.
- Parameters:
- GNetworkX graph or list of nodes
A position will be assigned to every node in G.
- nodeslist or container
Nodes in one node set of the bipartite graph. This set will be placed on left or top.
- alignstring (default=’vertical’)
The alignment of nodes. Vertical or horizontal.
- scalenumber (default: 1)
Scale factor for positions.
- centerarray-like or None
Coordinate pair around which to center the layout.
- aspect_rationumber (default=4/3):
The ratio of the width to the height of the layout.
- store_pos_asstr, default None
If non-None, the position of each node will be stored on the graph as an attribute with this string as its name, which can be accessed with
G.nodes[...][store_pos_as]
. The function still returns the dictionary.
- Returns:
- posdict
A dictionary of positions keyed by node.
Notes
This algorithm currently only works in two dimensions and does not try to minimize edge crossings.
Examples
>>> G = nx.bipartite.gnmk_random_graph(3, 5, 10, seed=123) >>> top = nx.bipartite.sets(G)[0] >>> pos = nx.bipartite_layout(G, top) >>> # supress the returned dict and store on the graph directly >>> _ = nx.bipartite_layout(G, top, store_pos_as="pos") >>> nx.get_node_attributes(G, "pos") {0: array([-1. , -0.6]), 1: array([-1., 0.]), 2: array([-1. , 0.6]), 3: array([ 0.6, -0.6]), 4: array([ 0.6, -0.3]), 5: array([0.6, 0. ]), 6: array([0.6, 0.3]), 7: array([0.6, 0.6])}