spiral_layout#
- spiral_layout(G, scale=1, center=None, dim=2, resolution=0.35, equidistant=False, store_pos_as=None)[source]#
Position nodes in a spiral layout.
- Parameters:
- GNetworkX graph or list of nodes
A position will be assigned to every node in G.
- scalenumber (default: 1)
Scale factor for positions.
- centerarray-like or None
Coordinate pair around which to center the layout.
- dimint, default=2
Dimension of layout, currently only dim=2 is supported. Other dimension values result in a ValueError.
- resolutionfloat, default=0.35
The compactness of the spiral layout returned. Lower values result in more compressed spiral layouts.
- equidistantbool, default=False
If True, nodes will be positioned equidistant from each other by decreasing angle further from center. If False, nodes will be positioned at equal angles from each other by increasing separation further from center.
- 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.
Examples
>>> G = nx.path_graph(4) >>> pos = nx.spiral_layout(G) >>> nx.draw(G, pos=pos) >>> # suppress the returned dict and store on the graph directly >>> _ = nx.spiral_layout(G, store_pos_as="pos") >>> nx.get_node_attributes(G, "pos") {0: array([-0.64153279, -0.68555087]), 1: array([-0.03307913, -0.46344795]), 2: array([0.34927952, 0.14899882]), 3: array([0.32533239, 1. ])}