xgi.drawing.layout

Algorithms to compute node positions for drawing.

Functions

xgi.drawing.layout.random_layout(H, center=None, seed=None)[source]

Position nodes uniformly at random in the unit square.

For every node, a position is generated by choosing each of dim coordinates uniformly at random on the interval [0.0, 1.0). NumPy (http://scipy.org) is required for this function.

Parameters:
  • H (Hypergraph or SimplicialComplex) – A position will be assigned to every node in HG.

  • center (array-like, optional) – Coordinate pair around which to center the layout. If None (default), does not center the positions.

  • seed (int, optional) – Set the random state for deterministic node layouts. If int, seed is the seed used by the random number generator, If None (default), random numbers are sampled from the numpy random number generator without initialization.

Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Notes

This function proceeds exactly as NetworkX does.

Examples

>>> import xgi
>>> N = 50
>>> ps = [0.1, 0.01]
>>> H = xgi.random_hypergraph(N, ps)
>>> pos = xgi.random_layout(H)
xgi.drawing.layout.pairwise_spring_layout(H, seed=None, k=None, **kwargs)[source]

Position the nodes using Fruchterman-Reingold force-directed algorithm using the graph projection of the hypergraph or the hypergraph constructed from the simplicial complex.

Parameters:
  • H (Hypergraph or SimplicialComplex) – A position will be assigned to every node in H.

  • seed (int, optional) – Set the random state for deterministic node layouts. If int, seed is the seed used by the random number generator, If None (default), random numbers are sampled from the numpy random number generator without initialization.

  • k (float) – The spring constant of the links. When k=None (default), k = 1/sqrt(N). For more information, see the documentation for the NetworkX spring_layout() function.

  • kwargs – Optional arguments for the NetworkX spring_layout() function. See https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.spring_layout.html

Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Notes

If a simplicial complex is provided the results will be based on the hypergraph constructed from its maximal simplices.

Examples

>>> import xgi
>>> N = 50
>>> ps = [0.1, 0.01]
>>> H = xgi.random_hypergraph(N, ps)
>>> pos = xgi.pairwise_spring_layout(H)
xgi.drawing.layout.barycenter_spring_layout(H, return_phantom_graph=False, seed=None, k=None, **kwargs)[source]

Position the nodes using Fruchterman-Reingold force-directed algorithm using an augmented version of the the graph projection of the hypergraph (or simplicial complex), where phantom nodes (barycenters) are created for each edge composed by more than two nodes. If a simplicial complex is provided the results will be based on the hypergraph constructed from its maximal simplices.

Parameters:
  • H (xgi Hypergraph or SimplicialComplex) – A position will be assigned to every node in H.

  • return_phantom_graph (bool (default=False)) – If True the function returns also the augmented version of the the graph projection of the hypergraph (or simplicial complex).

  • seed (int, RandomState instance or None optional (default=None)) – Set the random state for deterministic node layouts. If int, seed is the seed used by the random number generator, If None (default), random numbers are sampled from the numpy random number generator without initialization.

  • k (float) – The spring constant of the links. When k=None (default), k = 1/sqrt(N). For more information, see the documentation for the NetworkX spring_layout() function.

  • kwargs – Optional arguments for the NetworkX spring_layout() function. See https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.spring_layout.html

Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> import xgi
>>> N = 50
>>> ps = [0.1, 0.01]
>>> H = xgi.random_hypergraph(N, ps)
>>> pos = xgi.barycenter_spring_layout(H)
xgi.drawing.layout.weighted_barycenter_spring_layout(H, return_phantom_graph=False, seed=None, k=None, **kwargs)[source]

Position the nodes using Fruchterman-Reingold force-directed algorithm.

This uses an augmented version of the the graph projection of the hypergraph (or simplicial complex), where phantom nodes (barycenters) are created for each edge of order d>1 (composed by more than two nodes). Weights are assigned to all hyperedges of order 1 (links) and to all connections to phantom nodes within each hyperedge to keep them together. Weights scale as the order d. If a simplicial complex is provided the results will be based on the hypergraph constructed from its maximal simplices.

Parameters:
  • H (Hypergraph or SimplicialComplex) – A position will be assigned to every node in H.

  • return_phantom_graph (bool (default=False)) – If True the function returns also the augmented version of the the graph projection of the hypergraph (or simplicial complex).

  • seed (int, RandomState instance or None optional (default=None)) – Set the random state for deterministic node layouts. If int, seed is the seed used by the random number generator, If None (default), random numbers are sampled from the numpy random number generator without initialization.

  • k (float) – The spring constant of the links. When k=None (default), k = 1/sqrt(N). For more information, see the documentation for the NetworkX spring_layout() function.

  • kwargs – Optional arguments for the NetworkX spring_layout() function. See https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.spring_layout.html

Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> import xgi
>>> N = 50
>>> ps = [0.1, 0.01]
>>> H = xgi.random_hypergraph(N, ps)
>>> pos = xgi.weighted_barycenter_spring_layout(H)
xgi.drawing.layout.pca_transform(pos, theta=0, degrees=True)[source]

Transforms the positions of the nodes based on the principal components.

Parameters:
  • pos (dict of numpy arrays) – The output from any layout function

  • theta (float, optional) – The angle between the horizontal axis and the principal axis measured counterclockwise, by default 0.

  • degrees (bool, optional) – Whether the angle specified is in degrees (True) or in radians (False), by default True.

Returns:

The transformed positions.

Return type:

dict of numpy arrays

xgi.drawing.layout.circular_layout(H, center=None, radius=None)[source]

Position nodes on a circle.

Parameters:
  • H (Hypergraph or SimplicialComplex) – A position will be assigned to every node in H.

  • center (array-like or None) – Coordinate pair around which to center the layout. If None set to [0,0]

  • radius (float or None (default=None)) – Radius of the circle on which to draw the nodes, if None set to 1.0.

Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

xgi.drawing.layout.spiral_layout(H, center=None, resolution=0.35, equidistant=False)[source]

Position nodes in a spiral layout.

Parameters:
  • H (Hypergraph or SimplicialComplex) – A position will be assigned to every node in H.

  • center (array-like or None) – Coordinate pair around which to center the layout. If None set to [0,0]

  • resolution (float, default=0.35) – The compactness of the spiral layout returned. Lower values result in more compressed spiral layouts.

  • equidistant (bool, 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.

Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

xgi.drawing.layout.barycenter_kamada_kawai_layout(H, return_phantom_graph=False, **kwargs)[source]

Position nodes using Kamada-Kawai path-length cost-function using an augmented version of the the graph projection of the hypergraph (or simplicial complex), where phantom nodes (barycenters) are created for each edge composed by more than two nodes. If a simplicial complex is provided the results will be based on the hypergraph constructed from its maximal simplices.

Parameters:
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict