Engaging plots, made easy.

Easily turn your data into engaging visualizations. Powerful API for coders. Powerful app for everyone.

main.py
notebook.ipynb
main.rs
from plotapi import Chord

Chord(matrix, names).show()

Visualizations Chord

Linked data table

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


Sample data

Let's import PlotAPI and load our sample data.

from plotapi import Chord

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"]

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 string, or using a pandas DataFrame .to_csv(index=False).

data_table = """Genre 1,Genre 2,Title
Action,Thriller,The PlotAPI Horror
Action,Fantasy,Lord of the PlotAPI
Action,Thriller,Action for PlotAPI
Action,Drama,Feeling the PlotAPI
Action,Comedy,PlotAPI Turbo Force"""

Demonstration

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.

Chord(
    matrix,
    names,
    width=400,
    margin=20,
    curved_labels=True,
    data_table=data_table,
    data_table_column_width=80,
).show()
PlotAPI - Chord Diagram

We've shrunk this demonstration

We've shrunk this demonstration to fit within the Docs content area. Under normal circumstances, it will have more room to breathe!

Customizations

The data table supports optional customizations. Let's demonstrate these below.

  • data_table_show_indices will hide the index columns, in this case Genre 1 and Genre 2.
  • data_table_unique_column will allow us to specify a unique column, e.g. for instances where an item appears multiple times because it has multiple co-occurrences. In this case, it would be a movie that has 3 or more genres. We don't want them to appear in the same data table selection, so we can specify a unique column (usually the name of the item) here.
data_table = """Genre 1,Genre 2,Title
Action,Thriller,The PlotAPI Horror
Action,Fantasy,Lord of the PlotAPI
Action,Thriller,Action for PlotAPI
Action,Drama,Action for PlotAPI
Action,Drama,Feeling the PlotAPI
Action,Comedy,PlotAPI Turbo Force"""

In the table above we now have:

Action,Thriller,Action for PlotAPI
Action,Drama,Action for PlotAPI

Without data_table_unique_column, we'd have the following. Hover over Action and we'll see Action for PlotAPI listed twice.

Chord(
    matrix,
    names,
    width=400,
    margin=20,
    label_style="radial",
    data_table=data_table,
    data_table_column_width=200,
    data_table_show_indices=False,
).show()
PlotAPI - Chord Diagram

However, if we set data_table_unique_column="Title", we only see unique items for on each selection.

Chord(
    matrix,
    names,
    width=400,
    margin=20,
    label_style="radial",
    data_table=data_table,
    data_table_column_width=200,
    data_table_show_indices=False,
    data_table_unique_column="Title"
).show()
PlotAPI - Chord Diagram
Previous
Chord