Skip to main content

Force Directed Layout Algorithms for Python

This package provides 3 force directed layout algorithms implemented in Python.

Basic Usage

These algorithms are designed for the visualisation of high-dimensional datasets using force-directed graph drawing methods. Datasets are expected to be a numpy array with shape (N, D) where N is the size of the dataset and D is the number of dimensions.

# other imports
import matplotlib.pyplot as plt
import numpy as np

# import the package
import forcelayout as fl

# Need a dataset to visualise
dataset = np.array([[1, 1],
                    [1, 3],
                    [2, 2]])

# Need to use the brute force algorithm on a dataset this small
# (not recommended for larger datasets)
layout = fl.draw_spring_layout(dataset=dataset, algorithm=fl.SpringForce)

plt.show()

Functions

fl.draw_spring_layout():

Draw a spring layout diagram of the dataset. Returns the instance of the algorithm.

  • dataset: np.ndarray: 2d array of the data to lay out
  • algorithm: fl.BaseSpringLayout: The algorithm class to draw the spring layout diagram. One of the following:
    • fl.SpringForce
    • fl.NeighbourSampling
    • fl.Hybrid
    • fl.Pivot
  • iterations: int: number of force iterations to perform on the layout (when using the Hybrid algorithm this is the number of force iterations performed on the original sample).
  • hybrid_remainder_layout_iterations: int: number of force iterations to perform on each child of the remainder subset when using the Hybrid or Pivot algorithm.
  • hybrid_refine_layout_iterations: int: number of force iterations to perform on the whole layout after the remainder layout stage.
  • pivot_set_size: int: number of pivot nodes if algorithm=fl.Pivot.
  • sample_set_size: int: size of random sample set.
  • neighbour_set_size: int: size of neighbour set for neighbour sampling stages.
  • distance: Callable[[np.ndarray, np.ndarray], float]: function to determine the high dimensional distance between two datapoints of shape (1, D) and return a float representing the dissimilarity.
  • alpha: float: opacity of nodes in the diagram in range [0-1].
  • size: float: size of node to draw passed to matplotlib.pyplot.scatter(s=size).
  • color_by: Callable[[np.ndarray], float]: function to colour nodes by converting a (1, D) datapoint to a float to be expressed through the color_map.
  • color_map: str: string name or matplotlib colour map to use with color_by function.
  • annotate: Callable[[Node, int], str]: callback function for annotating nodes when hovered, given the node being hovered and the index in dataset.
  • algorithm_highlights: bool: allow on click of data point to highlight important nodes for the algorithm.
    • fl.NeighbourSampling: neighbour nodes.
    • fl.Hybrid: sample set nodes.
    • fl.Pivot: pivot nodes.

fl.draw_spring_layout_animated()

Draw a spring layout diagram of the data using the given algorithm. Returns a matplotlib.animation.FuncAnimation. Call plt.show() to view the animation. Parameters are the same as fl.draw_spring_layout() with one extra:

  • interval: int: milliseconds between each frame. If this is set low it will be limited by the run time of the algorithm.

fl.spring_layout()

Create an instance of a spring layout algorithm without running it. Uses the same parameters as fl.draw_spring_layout without ones specific to drawing.

Metadata

Release files for forcelayout 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for forcelayout 1.0.5
File Size Uploaded Provenance
forcelayout-1.0.5.tar.gz 13.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for forcelayout 1.0.5
File Interpreter ABI Platform
forcelayout-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 34.6 kB

Release files / forcelayout-1.0.5.tar.gz

Download URL forcelayout-1.0.5.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5575724857d09fda3ddecbe32ffaf82a416bef0293e5c6d3f2146db48788d9de
BLAKE2b-256 checksum
How to use checksums
947dfee49855e8c72ef0df76f7f35ad800dc5f4efb02d424be5dbc3b5a8a35b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Release files / forcelayout-1.0.5-py3-none-any.whl

Download URL forcelayout-1.0.5-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a86f576aed5f7dd83f5ee71a0e389a9115fa8a94d598b29d32b81cffd36bfd13
BLAKE2b-256 checksum
How to use checksums
a1b3ead95d14a61d17585bb1ae768444dc11a5f2b0db2d8aea15d1c9dac9aec7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Security for forcelayout 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page