Skip to main content

The ForceAtlas2 algorithm for Python (and NetworkX)

Project description

This is a port of Gephi’s ForceAtlas2 layout algorithm to Python 2 and Python 3 (with a wrapper for NetworkX).


The only strict dependency is Numpy. Cython is highly recommended, as it will speed it up by a factor of 10-100, depending on the graph. Both can be installed with:

pip install numpy pip install cython

To use the NetworkX wrapper function, you obviously need NetworkX.

Then to install this package, it is the typical:

python install

Example usage

Two core functions are defined:

  • forceatlas2.forceatlas2 takes an adjacency matrix and optionally initial positions and other optional arguments. It uses this to calculate a layout.
  • forceatlas2.forceatlas2_networkx_layout takes a NetworkX graph and returns a NetworkX-compatible layout.

To use within NetworkX:

import matplotlib.pyplot as plt import networkx import random import forceatlas2 G = networkx.karate_club_graph() pos = { i : (random.random(), random.random()) for i in G.nodes()} # Optionally specify positions as a dictionary l = forceatlas2.forceatlas2_networkx_layout(G, pos, niter=1000) # Optionally specify iteration count networkx.draw_networkx(G, l)

Note that my coding style is non-Pythonic, as I don’t use function docstrings. You will have to take a look at the function definition in to see a description of all of the potential arguments.

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ForceAtlas2, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size ForceAtlas2-1.0.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page