Plotapi, beautiful by default.

Let plotapi do the heavy lifting – enabling beautiful interactive visualisations with a single line of code (instead of hundreds).

Get Plotapi

Bipartite (Divided) Chord Diagrams

Preamble

In [1]:
from plotapi import Chord

Chord.set_license("your username", "your license key")

Introduction

The bipartite feature of Plotapi Chord makes the biggest difference to the presentation and interpretation of the diagram. It splits the diagram in two, meaning relationships now happen between two different categorical sets.

As we can see, we have set our license details in the preamble with Chord.set_license()

Dataset

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [6]:
matrix = [
    [0, 0, 0, 1, 4, 1],
    [0, 0, 0, 1, 3, 2],
    [0, 0, 0, 1, 2, 2],
    [1, 1, 1, 0, 0, 0],
    [4, 3, 2, 0, 0, 0],
    [1, 2, 2, 0, 0, 0],
]

names = ["Right 1", "Right 2", "Right 3", "Left 3", "Left 2", "Left 1"]
colors = ["#7400B8", "#5E60CE", "#5684D6", "#56CFE1", "#64DFDF", "#80FFDB"]

It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [7]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)
Out[7]:
Right 1 Right 2 Right 3 Left 3 Left 2 Left 1
Right 1 0 0 0 1 4 1
Right 2 0 0 0 1 3 2
Right 3 0 0 0 1 2 2
Left 3 1 1 1 0 0 0
Left 2 4 3 2 0 0 0
Left 1 1 2 2 0 0 0

Visualisation

The bipartite mode is activated by setting the bipartite parameter to True.

  • bipartite enables/disables the bipartite chord diagram mode.
  • bipartite_idx sets the dividing point of the matrix.
  • bipartite_size sets the size of the spacing that creates the divide.
  • colors must be explicitly listed in bipartite mode.

We have 6 categories in our matrix, and we wish to divide them directly down the middle, so our bipartite_idx will be $3$.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [10]:
Chord(matrix, names, colors=colors, bipartite=True, bipartite_idx=3).show()
Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

Made with Plotapi

You can create beautiful, interactive, and engaging visualisations like this one in any programming language with Plotapi.

Get the Books

Enjoying these notebooks and want more on the subject? Check out the practical books on Data Science, Visualisation, and Evolutionary Algorithms.

Get the books