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

Equal-sized Segments

Made with Plotapi

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

Preamble

In [2]:
from plotapi import Chord

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

Introduction

It may be desirable to have equal-sized segments in our Chord Diagram. This is possible with Plotapi, and makes use of the colored_diagonals feature. The idea is to determine the max frequency in our plot, and set all the diagonals to that value. Let's assume that is $20$ for this example.

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 [3]:
matrix = [
    [20, 0, 0, 0, 0, 0],
    [0, 20, 0, 0, 0, 0],
    [0, 0, 20, 0, 0, 0],
    [0, 0, 0, 20, 0, 0],
    [0, 0, 0, 0, 20, 0],
    [0, 0, 0, 0, 0, 20],
]

names=['one','two','three','four','five','six']

Chord(matrix, names, title="Diagonals not coloured", 
      colored_diagonals=False).show()
Plotapi - Chord Diagram

We can see above that this creates a chord diagram with equal-sized segments. All we need to do now is introduce our relationships, and subtract them from the corresponding diagonal value.

In [5]:
matrix = [
    [11, 4, 5, 0, 0, 0],
    [4, 14, 2, 0, 0, 0],
    [5, 2, 13, 0, 0, 0],
    [0, 0, 0, 20, 0, 0],
    [0, 0, 0, 0, 20, 0],
    [0, 0, 0, 0, 0, 20],
]

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

In [6]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)
Out[6]:
one two three four five six
one 11 4 5 0 0 0
two 4 14 2 0 0 0
three 5 2 13 0 0 0
four 0 0 0 20 0 0
five 0 0 0 0 20 0
six 0 0 0 0 0 20

Visualisation

With our matrix prepared, we can use Plotapi with colored_diagonals=False to create a diagram with equal-sized segments and some ribbons between categories. We could add some padding to separate them too.

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 [20]:
Chord(matrix, names, colors="set2",
      title="Diagonals not coloured", 
      colored_diagonals=False, padding=0.2).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 with Plotapi in any programming language.

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