shell_layout#
- shell_layout(G, nlist=None, rotate=None, scale=1, center=None, dim=2, store_pos_as=None)[source]#
Position nodes in concentric circles.
- Parameters:
- GNetworkX graph or list of nodes
A position will be assigned to every node in G.
- nlistlist of lists
List of node lists for each shell.
- rotateangle in radians (default=pi/len(nlist))
Angle by which to rotate the starting position of each shell relative to the starting position of the previous shell. To recreate behavior before v2.5 use rotate=0.
- scalenumber (default: 1)
Scale factor for positions.
- centerarray-like or None
Coordinate pair around which to center the layout.
- dimint
Dimension of layout, currently only dim=2 is supported. Other dimension values result in a ValueError.
- 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
- Raises:
- ValueError
If dim != 2
Notes
This algorithm currently only works in two dimensions and does not try to minimize edge crossings.
Examples
>>> G = nx.path_graph(4) >>> shells = [[0], [1, 2, 3]] >>> pos = nx.shell_layout(G, shells) >>> # supress the returned dict and store on the graph directly >>> _ = nx.shell_layout(G, shells, store_pos_as="pos") >>> nx.get_node_attributes(G, "pos") {0: array([0., 0.]), 1: array([-5.00000000e-01, -4.37113883e-08]), 2: array([ 0.24999996, -0.43301272]), 3: array([0.24999981, 0.43301281])}