Chord Diagram
In [1]:
Copied!
# %pip install pycirclize
# %pip install pycirclize
1. Chord Diagram From Matrix¶
pyCirclize can plot a Chord Diagram(wiki) from matrix data like circlize or Circos Table Viewer.
In [2]:
Copied!
from pycirclize import Circos
import pandas as pd
# Create matrix dataframe (3 x 6)
row_names = ["S1", "S2", "S3"]
col_names = ["E1", "E2", "E3", "E4", "E5", "E6"]
matrix_data = [
[4, 14, 13, 17, 5, 2],
[7, 1, 6, 8, 12, 15],
[9, 10, 3, 16, 11, 18],
]
matrix_df = pd.DataFrame(matrix_data, index=row_names, columns=col_names)
# Initialize from matrix (Can also directly load tsv matrix file)
circos = Circos.initialize_from_matrix(
matrix_df,
start=-265,
end=95,
space=5,
r_lim=(93, 100),
cmap="tab10",
label_kws=dict(r=94, size=12, color="white"),
link_kws=dict(ec="black", lw=0.5),
)
print(matrix_df)
fig = circos.plotfig()
from pycirclize import Circos
import pandas as pd
# Create matrix dataframe (3 x 6)
row_names = ["S1", "S2", "S3"]
col_names = ["E1", "E2", "E3", "E4", "E5", "E6"]
matrix_data = [
[4, 14, 13, 17, 5, 2],
[7, 1, 6, 8, 12, 15],
[9, 10, 3, 16, 11, 18],
]
matrix_df = pd.DataFrame(matrix_data, index=row_names, columns=col_names)
# Initialize from matrix (Can also directly load tsv matrix file)
circos = Circos.initialize_from_matrix(
matrix_df,
start=-265,
end=95,
space=5,
r_lim=(93, 100),
cmap="tab10",
label_kws=dict(r=94, size=12, color="white"),
link_kws=dict(ec="black", lw=0.5),
)
print(matrix_df)
fig = circos.plotfig()
E1 E2 E3 E4 E5 E6 S1 4 14 13 17 5 2 S2 7 1 6 8 12 15 S3 9 10 3 16 11 18
1-2. Example2 (10 x 10)¶
This example uses the 10 x 10 matrix data randomly generated by Circos Table Viewer
In [3]:
Copied!
from pycirclize import Circos
import pandas as pd
# Create matrix data (10 x 10)
row_names = list("ABCDEFGHIJ")
col_names = row_names
matrix_data = [
[51, 115, 60, 17, 120, 126, 115, 179, 127, 114],
[108, 138, 165, 170, 85, 221, 75, 107, 203, 79],
[108, 54, 72, 123, 84, 117, 106, 114, 50, 27],
[62, 134, 28, 185, 199, 179, 74, 94, 116, 108],
[211, 114, 49, 55, 202, 97, 10, 52, 99, 111],
[87, 6, 101, 117, 124, 171, 110, 14, 175, 164],
[167, 99, 109, 143, 98, 42, 95, 163, 134, 78],
[88, 83, 136, 71, 122, 20, 38, 264, 225, 115],
[145, 82, 87, 123, 121, 55, 80, 32, 50, 12],
[122, 109, 84, 94, 133, 75, 71, 115, 60, 210],
]
matrix_df = pd.DataFrame(matrix_data, index=row_names, columns=col_names)
# Initialize from matrix (Can also directly load tsv matrix file)
circos = Circos.initialize_from_matrix(
matrix_df,
space=3,
r_lim=(93, 100),
cmap="tab10",
ticks_interval=500,
label_kws=dict(r=94, size=12, color="white"),
)
print(matrix_df)
fig = circos.plotfig()
from pycirclize import Circos
import pandas as pd
# Create matrix data (10 x 10)
row_names = list("ABCDEFGHIJ")
col_names = row_names
matrix_data = [
[51, 115, 60, 17, 120, 126, 115, 179, 127, 114],
[108, 138, 165, 170, 85, 221, 75, 107, 203, 79],
[108, 54, 72, 123, 84, 117, 106, 114, 50, 27],
[62, 134, 28, 185, 199, 179, 74, 94, 116, 108],
[211, 114, 49, 55, 202, 97, 10, 52, 99, 111],
[87, 6, 101, 117, 124, 171, 110, 14, 175, 164],
[167, 99, 109, 143, 98, 42, 95, 163, 134, 78],
[88, 83, 136, 71, 122, 20, 38, 264, 225, 115],
[145, 82, 87, 123, 121, 55, 80, 32, 50, 12],
[122, 109, 84, 94, 133, 75, 71, 115, 60, 210],
]
matrix_df = pd.DataFrame(matrix_data, index=row_names, columns=col_names)
# Initialize from matrix (Can also directly load tsv matrix file)
circos = Circos.initialize_from_matrix(
matrix_df,
space=3,
r_lim=(93, 100),
cmap="tab10",
ticks_interval=500,
label_kws=dict(r=94, size=12, color="white"),
)
print(matrix_df)
fig = circos.plotfig()
A B C D E F G H I J A 51 115 60 17 120 126 115 179 127 114 B 108 138 165 170 85 221 75 107 203 79 C 108 54 72 123 84 117 106 114 50 27 D 62 134 28 185 199 179 74 94 116 108 E 211 114 49 55 202 97 10 52 99 111 F 87 6 101 117 124 171 110 14 175 164 G 167 99 109 143 98 42 95 163 134 78 H 88 83 136 71 122 20 38 264 225 115 I 145 82 87 123 121 55 80 32 50 12 J 122 109 84 94 133 75 71 115 60 210