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

Linked Data Table


In [ ]:
from plotapi import Chord

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


Plotapi Chord supports a linked data table. This means as you hover over segments and ribbons in the Chord diagram, a data table will be filtering in real-time to show more information.

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


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

In [ ]:
matrix = [
    [0, 5, 6, 4, 7, 4],
    [5, 0, 5, 4, 6, 5],
    [6, 5, 0, 4, 5, 5],
    [4, 4, 4, 0, 5, 5],
    [7, 6, 5, 5, 0, 4],
    [4, 5, 5, 5, 4, 0],

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]

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

In [ ]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)
Out[ ]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

To make use of the linked data table, we need to provide some data in CSV format. This could be loaded through a file, directly in a strong, or using a pandas DataFrame (.to_csv(index=False)).

In [ ]:
data_table='''Genre 1,Genre 2,Awesome
Thriller,Action,The Plotapi
Thriller,Action,Action Plotapi
Thriller,Drama,Feeling Plotapi
Thriller,Comedy,Plotapi Force'''


We'll enable the linked data table by passing data into the data_table parameter, and we'll modify the data_table_column_width by setting it to a smaller value of $80$.

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 [9]:
Chord(matrix, names, width=400, margin=20, curved_labels=True,
      data_table=data_table, data_table_column_width=80).show()
Plotapi - Chord Diagram

Data table mode includes the "locking" feature. Try clicking on the Thriller segment and you will see a padlock icon appear in the top right, and until you click somewhere again the current selection will persist.

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