easygraph.functions.drawing.positioning module#
- easygraph.functions.drawing.positioning.circular_position(G, center=None, scale=1)[source]#
Position nodes on a circle, the dimension is 2.
- Parameters:
G (easygraph.Graph or easygraph.DiGraph) – A position will be assigned to every node in G
center (array-like or None, optional (default : None)) – Coordinate pair around which to center the layout
scale (number, optional (default : 1)) – Scale factor for positions
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
- easygraph.functions.drawing.positioning.kamada_kawai_layout(G, dist=None, pos=None, weight='weight', scale=1, center=None, dim=2)[source]#
Position nodes using Kamada-Kawai basic-length cost-function.
- Parameters:
G (graph or list of nodes) – A position will be assigned to every node in G.
dist (dict (default=None)) – A two-level dictionary of optimal distances between nodes, indexed by source and destination node. If None, the distance is computed using shortest_path_length().
pos (dict or None optional (default=None)) – Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use circular_layout() for dim >= 2 and a linear layout for dim == 1.
weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1.
scale (number (default: 1)) – Scale factor for positions.
center (array-like or None) – Coordinate pair around which to center the layout.
dim (int) – Dimension of layout.
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
Examples
>>> pos = eg.kamada_kawai_layout(G)
- easygraph.functions.drawing.positioning.random_position(G, center=None, dim=2, random_seed=None)[source]#
Returns random position for each node in graph G.
- Parameters:
G (easygraph.Graph or easygraph.DiGraph) –
center (array-like or None, optional (default : None)) – Coordinate pair around which to center the layout
dim (int, optional (default : 2)) – Dimension of layout
random_seed (int or None, optional (default : None)) – Seed for RandomState instance
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
- easygraph.functions.drawing.positioning.rescale_position(pos, scale=1)[source]#
Returns scaled position array to (-scale, scale) in all axes.
- Parameters:
pos (numpy array) – positions to be scaled. Each row is a position.
scale (number, optional (default : 1)) – The size of the resulting extent in all directions.
- Returns:
pos – scaled positions. Each row is a position.
- Return type:
numpy array
- easygraph.functions.drawing.positioning.shell_position(G, nlist=None, scale=1, center=None)[source]#
Position nodes in concentric circles, the dimension is 2.
- Parameters:
G (easygraph.Graph or easygraph.DiGraph) –
nlist (list of lists or None, optional (default : None)) – List of node lists for each shell.
scale (number, optional (default : 1)) – Scale factor for positions.
center (array-like or None, optional (default : None)) – Coordinate pair around which to center the layout.
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
Notes
This algorithm currently only works in two dimensions and does not try to minimize edge crossings.