pke1029 / open-chord

OpenChord is a Python library for creating chord diagrams.
GNU General Public License v3.0
8 stars 4 forks source link

Compare the chord diagram of two similar matrix inputs #2

Open TomHsiung opened 2 months ago

TomHsiung commented 2 months ago

import openchord as ocd import numpy as np matrix = [ [2, 1, 0, 1, 1], [0, 29, 3, 18, 15], [0, 100, 0, 1, 0], [3, 22, 0, 15, 10], [7, 15, 1, 5, 9] ] labels = ['Danger', 'Optimal', 'Over', 'Suboptimal', 'Under'] fig = ocd.Chord(matrix, labels) fig.gradient_style = "default" fig.arc_thickness = 0.05 fig.gap_size = 0.05 fig.ribbon_stiffness = 0.6 fig.radius = 300 fig.plot_area = {"x": -750, "y": -500, "w": 2000, "h": 2000}

fig.colormap = ['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880']

fig.save_svg("/Users/tomhsiung/chord_diagram.svg")`

This makes a chord diagram of,

Screenshot 2024-08-22 at 5 48 29 PM

Notice the relationship between category 'Over' and 'Optimal'. Next, lets change the cell number of column 3 row 2 from 3 to 0.

import openchord as ocd import numpy as np matrix = [ [2, 1, 0, 1, 1], [0, 29, 0, 18, 15], [0, 100, 0, 1, 0], [3, 22, 0, 15, 10], [7, 15, 1, 5, 9] ] labels = ['Danger', 'Optimal', 'Over', 'Suboptimal', 'Under'] fig = ocd.Chord(matrix, labels) fig.gradient_style = "default" fig.arc_thickness = 0.05 fig.gap_size = 0.05 fig.ribbon_stiffness = 0.6 fig.radius = 300 fig.plot_area = {"x": -750, "y": -500, "w": 2000, "h": 2000}

fig.colormap = ['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880']

fig.save_svg("/Users/tomhsiung/chord_diagram.svg")

Then, we have this new chord diagram with a large portion of blank.

Screenshot 2024-08-22 at 5 50 25 PM

The difference between the two matrices is that the first matrix has a bilateral flow between category 'Over' and 'Optimal'. The second matrix, in contrast, only has unilateral flow from 'Optimal' to 'Over'. This blank is difficult to interpret for those who are not familiar with chord diagram.