Chord Diagram in Python

Viewed 2673

Hi have a DataFrame along those lines:

Source   Target    Value     
A        B         10       
A        C         5    
A        D         15
A        E         20
A        F         3
B        A         3
B        G         15
F        D         13
F        E         2
E        A         20
E        D         6

And want to draw this Chord Diagram using Python:

enter image description here

I found this chord diagram in the following link: https://www.data-to-viz.com/graph/chord.html. It states that this plot is made using the circlize library (which I believe is an R library). Is there a way to do this in Python as well?

I would also like to be able to choose the color for each element (A to G in my case) and write on the circumference as shown in the example image.

Here is another DataFrame for example with the colors:

Name   Color
A      Red
B      Orange
C      Yellow
D      Green
E      Blue
F      Purple

Also an arrow tip to help distinguish the source from the target, if possible, as in the example image.

I can't find a ready available library in python that does this for me.

3 Answers

Building on @mportes answer,

  • The Chord library now is a paid service, included in plotapi.
  • Plotting chord diagrams in plotly seems pretty complicated and the example is only for v3.

So the solution that worked best for me is using Holoviews. Here is an example plot. I don't know if you can make arrows, but the direction from source to target is easily identifiable because the chords always have the source color.

The page you share the link to has a Build your own section with a link to the Python Gallery. Here you can find three alternative ways to make a chord diagram in Python:

  • using the Chord library
  • using the Bokeh library
  • using the Plotly library

You could try PlotAPI (paid) - it's available as a Python package.

Here's a video on Chord diagrams from concept to Python code.

Related