I have a small dataset indicating flows in-between zones. I want to create a chord diagram, and each chord's width being proportional to its value.
My dataset is the following:
# Given data
data = {
'Unnamed: 0': ['North', 'Center', 'South'],
'North': [50, 100, 150],
'Center': [20, 80, 160],
'South': [70, 150, 230]
}
# Create a DataFrame and set 'Unnamed: 0' as the index
df = pd.DataFrame(data).set_index('Unnamed: 0')
# Transpose the DataFrame to get a square matrix
df = df.transpose()
So far I have tried using the library of the D3Blocks:
from d3blocks import D3Blocks
# Convert the DataFrame to the required format for d3blocks
df_reset = df.reset_index()
df_melted = pd.melt(df_reset, id_vars='index', var_name='target', value_name='weight')
df_melted = df_melted.rename(columns={'index': 'source'})
# Initialize d3blocks
d3 = D3Blocks()
# Plot the chord diagram
d3.chord(df_melted)
The code works. However, I cannot adjust the width of the chords connecting the zones based on their value as it is nicely done for other cases (Circular Chord Diagram in Python).
I also found another solution by using the PlotAPI (https://plotapi.com/), but it seems it is no longer for free.
Can you help me with making the chord diagram I need? Thanks in advance.