Skip to content

Commit

Permalink
Minor docstring/formatting touchups.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar committed Apr 3, 2024
1 parent ba43aea commit ce7ac60
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions networkx/drawing/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,24 +1137,20 @@ def forceatlas2_layout(
linlog=False,
dim=2,
):
"""Forceatlas2 layout for networkx
"""Forceatlas2 layout.
The ForceAtlas2 layout is a force-directed approach that
improves upon ForceAtlas by simplifying the parameters
[1]. It offers a good compromise between clustering and
spatially separating parts of the network. The layout
was originally designed and used by Gephi to visualize
The ForceAtlas2 layout is a force-directed approach that improves upon
ForceAtlas by simplifying the parameters [1]_. It offers a good compromise
between clustering and spatially separating parts of the network.
The layout was originally designed and used by Gephi to visualize
graphs in a continuous and interactive manner.
In the layout, nodes repulse each other similar to
oppositely charged particles, while edges attract like
to springs. The balance between the attractive and
repulsive forces produce visually pleasing layouts,
particularly for large graphs.
In the layout, nodes repulse each other similar to oppositely charged particles,
while edges attract like springs. The balance between the attractive and
repulsive forces produce visually pleasing layouts, particularly for large graphs.
The algorithm includes parameters for customization,
such as gravity (pull towards the center), scaling (size
of the layout) and jitter (random perturbations).
The algorithm includes parameters for customization, such as gravity (pull
towards the center), scaling (size of the layout) and jitter (random perturbations).
Parameters
----------
Expand All @@ -1165,47 +1161,44 @@ def forceatlas2_layout(
n_iter: number (default: 100)
Simulation steps
jitter_tolerance : number (default: 1.0)
Jitter tolerance for adjusting speed of layout convergence;
lower values are slower but yield more accuracy. Jitter controls
how much swinging is allowed. Values above 1 are discouraged.
Jitter helps break symmetries between similar parts of the graph
through random perturbations in the layout generation.
Jitter tolerance for adjusting speed of layout convergence; lower values
are slower but yield more accuracy. Jitter controls how much swinging is
allowed. Values above 1 are discouraged. Jitter helps break symmetries
between similar parts of the graph through random perturbations in the
layout generation.
scaling_ratio : number (default: 2.0)
Controls force scaling constants k_attraction and
k_repulsion
Controls force scaling constants k_attraction and k_repulsion
distributed_action : bool (default: False)
Normalizes the attraction forces according to the degree of the nodes
strong_gravity : bool (default: false)
Controls the "pull" to the center of mass of the
plot (0,0)
Controls the "pull" to the center of mass of the plot
adjust_sizes: bool (default: False)
Prevent node overlapping in the layout
dissuade_hubs : bool (default: false)
dissuade_hubs : bool (default: False)
Prevent hub clustering
edge_weight_influence : bool (default: False)
Generate layout with or without considering the edge
weights
Generate layout with or without considering the edge weights
linlog : bool (default: False)
Use log attraction rather than linear attraction
dim: number (default: 2)
Sets the dimensions of the layout. This parameter is ignored if pos is given.
Sets the dimensions of the layout. This parameter is ignored if `pos` is given.
Examples
--------
>>> import networkx as nx
>>> G = nx.florentine_families_graph()
>>> nx.draw(G, pos=nx.forceatlas2_layout(G))
[1] https://journals.plos.org/plosone/article/file?id=10.1371/journal.pone.0098679&type=printable
References
----------
.. [1] https://journals.plos.org/plosone/article/file?id=10.1371/journal.pone.0098679&type=printable
"""
import numpy as np

def estimate_factor(n, swing, traction, speed, speed_efficiency, jitter_tolerance):
"""
ForceAtlas2 helper function
Computes scaling factor for force
"""
"""Computes scaling factor for force."""

# estimate jitter
opt_jitter = 0.05 * np.sqrt(n)
Expand Down Expand Up @@ -1241,7 +1234,7 @@ def estimate_factor(n, swing, traction, speed, speed_efficiency, jitter_toleranc
else:
dim = len(next(iter(pos.values())))

# Scale the position of the node proportional to the @pos
# Scale the position of the node proportional to the pos
max_pos_range = 1
min_pos_range = 0
# check if we have a valid pos else just return (empty graph)
Expand Down Expand Up @@ -1275,7 +1268,7 @@ def estimate_factor(n, swing, traction, speed, speed_efficiency, jitter_toleranc
speed_efficiency = 1
swing = 1
traction = 1
for idx in range(n_iter):
for _ in range(n_iter):
# compute pairwise difference
diff = pos_arr[:, None] - pos_arr[None]
# compute pairwise distance
Expand Down

0 comments on commit ce7ac60

Please sign in to comment.