Skip to main content

Interactive force-directed graph in a jupyter notebook.

Project description

Plots an interactive force directed graph in a jupyter notebook, taking data from a dataframe of nodes and link weights.

Why d3fdgraph?

Working with data using python in the jupyter notebook provides many options for visualising that data.

The pandas library provides convenient common visualisations, and there’s always the venerable matplotlib for more bespoke plots. The new vega-lite library is enabled by default in jupyterlab.

Sometimes we want to plot the relationships between things as a graph of linked nodes.

The networkx library can plot graphs in a notebook but the plots are static, and only really suitable for smaller data.

Being able to interactively adjust graphs really helps explore larger data.

That’s what d3fdgraph does.

Installing d3fdgraph

Installing d3fdgraph is easy.

pip install d3fdgraph

This has been tested with Anaconda Python 3.

How To Use

To use d3fdgraph in a notebook we import the library.

import d3fdgraph

d3fdgraph takes data in the form of a pandas dataframe.

That dataframe must have 3 columns:

  • The first column contains the nodes at the start of a link.

  • The second column contains the nodes at the end of a link.

  • The third column contains a link weight number. It must be more than 0.

The larger the weight, the more strongly related the two nodes at each end of this link.

Here is an example dataframe:

source

target

weight

apple

orange

1

apple

banana

2

orange

mango

2

orange

lemon

3

Each row is a link:

  • The first row is a link between apple and orange. These two are connected with a weight of 1.

  • The second row is a link between apple and banana. These two are more strongly related, with a weight 2.

  • The fourth row is the strongest link, with weight 3, between orange and lemon.

The column names don’t have to be source, target and weight. You can have different column names, but it is a good idea to use descriptive names.

The order of the 3 columns is what matters. d3fdgraph will use the first column as the source nodes, the second as the target, and the third as link weights.

To draw an interactive force directed graph of these nodes and links we simply pass this dataframe to the plot_force_directed_graph() function.

d3fdgraph.plot_force_directed_graph(dataframe)

Here is an example of a graph made from different data.

https://github.com/intuitivetextmining/d3fdgraph/blob/master/images/d3fdgraph_recipes.gif

You can use your pointer to drag nodes around to adjust the graph.

The nodes are labelled with the names of the nodes, as described in the pandas dataframe.

Example Notebook

A simple jupyter notebook showing how d3fdgraph can be used is here:

Note

Note that d3fdgraph is only useful in a jupyter notebook. It isn’t useful in a terminal, and hasn’t been tested in other kinds of python notebook.

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

d3fdgraph-0.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

d3fdgraph-0.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file d3fdgraph-0.3.tar.gz.

File metadata

  • Download URL: d3fdgraph-0.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for d3fdgraph-0.3.tar.gz
Algorithm Hash digest
SHA256 0d829959decb15b0274997a6d891357d1586d2d3c19cb54cacc8f74309f15014
MD5 b2dc3a50f1db5d410917d4f1a457ad98
BLAKE2b-256 1cbaa2869c2e5346da90bbfe4d43df3694619ad363e43f046095eab02bc4ca8c

See more details on using hashes here.

File details

Details for the file d3fdgraph-0.3-py3-none-any.whl.

File metadata

  • Download URL: d3fdgraph-0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for d3fdgraph-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 22c0e3e7720db01ba4bb8d1db167bad18fb6428538199b4db3159adebe814ea1
MD5 be7f307c29dc646e26b42b49708bcb6e
BLAKE2b-256 56ecff5a8997f793d59b77d841e9c12e421d1a680175e37ab0aa325f1a6f26e7

See more details on using hashes here.

Supported by

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