If your jobs include plotting data onto graphs to show insights, you may hear of the Circos chart for its fancy presentation. In fact, rather than good-looking, it is also great in terms of visualising complex relationships such as the connections between genes in genomic research. Of course, in the general Data Visualisation use cases, there are also some benefits such as more efficiently utilising the space, highlighting patterns with cycles, etc.
You may think drawing a Circos chart could be difficult, but I would say no. With an amazing visualisation called PyCirclize, you can do that extremely easily in Python.
In this article, I’m going to show you how to draw a very basic Circos diagram step by step. In the next article, I’ll add some real-world use cases and more complex charts using this library.
Let’s not waste too much time on how to install the library. It can be easily added to your Python environment using pip.
$ pip install pycirclize
Let’s have a look at how it works before drawing our first Circos chart.
Of course, before everything, we need to import the Circos module from the library package.
from pycirclize import Circos
Usually, we want to have multiple sectors for the circle. We need to initialise a Circos object with the sector metadata. The sectors need to be defined in a dictionary before passing it to the Circos constructor.
# Initialize circos sectors
sectors = "A": 1, "B": 2, "C": 3, "D": 4
circos = Circos(sectors, space=5)
The space specifies how much padding we want to add between the sectors. If it is set to zero, this will become a “pie chart”.
Next, loop in the sectors and render each sector with what we want to display in it.
for sector in circos.sectors…