5

Bipartite (Divided) Chord Diagrams

 2 years ago
source link: https://datacrayon.com/posts/plotapi/chord/bipartite-divided-chord-diagrams/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Preamble

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.

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.

import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

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 333.

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!

Chord(matrix, names, colors=colors, bipartite=True, bipartite_idx=3).show()

Plotapi - Chord Diagram

Right 1Right 2Right 3bipartiteLeft 3Left 2Left 1bipartiteProduced with Plotapi

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK