forceatlas2_layout#

forceatlas2_layout(G, pos=None, *, max_iter=100, jitter_tolerance=1.0, scaling_ratio=2.0, gravity=1.0, distributed_action=False, strong_gravity=False, node_mass=None, node_size=None, weight=None, dissuade_hubs=False, linlog=False, seed=None, dim=2)[source]#

Position nodes using the ForceAtlas2 force-directed layout algorithm.

This function applies the ForceAtlas2 layout algorithm [1] to a NetworkX graph, positioning the nodes in a way that visually represents the structure of the graph. The algorithm uses physical simulation to minimize the energy of the system, resulting in a more readable layout.

Parameters:
Gnx.Graph

A NetworkX graph to be laid out.

posdict or None, optional

Initial positions of the nodes. If None, random initial positions are used.

max_iterint (default: 100)

Number of iterations for the layout optimization.

jitter_tolerancefloat (default: 1.0)

Controls the tolerance for adjusting the speed of layout generation.

scaling_ratiofloat (default: 2.0)

Determines the scaling of attraction and repulsion forces.

distributed_attractionbool (default: False)

Distributes the attraction force evenly among nodes.

strong_gravitybool (default: False)

Applies a strong gravitational pull towards the center.

node_massdict or None, optional

Maps nodes to their masses, influencing the attraction to other nodes.

node_sizedict or None, optional

Maps nodes to their sizes, preventing crowding by creating a halo effect.

dissuade_hubsbool (default: False)

Prevents the clustering of hub nodes.

linlogbool (default: False)

Uses logarithmic attraction instead of linear.

seedint, RandomState instance or None optional (default=None)

Used only for the initial positions in the algorithm. Set the random state for deterministic node layouts. If int, seed is the seed used by the random number generator, if numpy.random.RandomState instance, seed is the random number generator, if None, the random number generator is the RandomState instance used by numpy.random.

dimint (default: 2)

Sets the dimensions for the layout. Ignored if pos is provided.

References

[1]

Jacomy, M., Venturini, T., Heymann, S., & Bastian, M. (2014). ForceAtlas2, a continuous graph layout algorithm for handy network visualization designed for the Gephi software. PloS one, 9(6), e98679. https://doi.org/10.1371/journal.pone.0098679

Examples

>>> import networkx as nx
>>> G = nx.florentine_families_graph()
>>> pos = nx.forceatlas2_layout(G)
>>> nx.draw(G, pos=pos)