Skip to main content

Force-directed layout algorithms for Python

Project description

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.

Project details


Download files

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

Source Distribution

forcelayout-1.0.5.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

forcelayout-1.0.5-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file forcelayout-1.0.5.tar.gz.

File metadata

  • Download URL: forcelayout-1.0.5.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for forcelayout-1.0.5.tar.gz
Algorithm Hash digest
SHA256 5575724857d09fda3ddecbe32ffaf82a416bef0293e5c6d3f2146db48788d9de
MD5 338c4e83b5c5b5f0fdc92a9235977f54
BLAKE2b-256 947dfee49855e8c72ef0df76f7f35ad800dc5f4efb02d424be5dbc3b5a8a35b9

See more details on using hashes here.

File details

Details for the file forcelayout-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: forcelayout-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for forcelayout-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a86f576aed5f7dd83f5ee71a0e389a9115fa8a94d598b29d32b81cffd36bfd13
MD5 03c2ff66148108521be4f9f1edd6498a
BLAKE2b-256 a1b3ead95d14a61d17585bb1ae768444dc11a5f2b0db2d8aea15d1c9dac9aec7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page