Skip to main content
`Ctrl`+`K`

# 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)

  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:
    G nx.Graph

      A NetworkX graph to be laid out.

    pos dict or None, optional

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

    max_iter int (default: 100)

      Number of iterations for the layout optimization.

    jitter_tolerance float (default: 1.0)

      Controls the tolerance for adjusting the speed of layout generation.

    scaling_ratio float (default: 2.0)

      Determines the scaling of attraction and repulsion forces.

    distributed_attraction bool (default: False)

      Distributes the attraction force evenly among nodes.

    strong_gravity bool (default: False)

      Applies a strong gravitational pull towards the center.

    node_mass dict or None, optional

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

    node_size dict or None, optional

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

    dissuade_hubs bool (default: False)

      Prevents the clustering of hub nodes.

    linlog bool (default: False)

      Uses logarithmic attraction instead of linear.

    seed int, 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.

    dim int (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)