Skip to main content

Circular visualization in Python

Project description

pyCirclize: Circular visualization in Python

Python3 OS License Latest PyPI version conda-forge CI

Table of contents

Overview

pyCirclize is a circular visualization python package implemented based on matplotlib. This package is developed for the purpose of easily and beautifully plotting circular figure such as Circos Plot and Chord Diagram in Python. In addition, useful genome and phylogenetic tree visualization methods for the bioinformatics field are also implemented. pyCirclize was inspired by circlize and pyCircos. More detailed documentation is available here.

pyCirclize_gallery.png
Fig.1 pyCirclize example plot gallery

Installation

Python 3.8 or later is required for installation.

Install PyPI package:

pip install pycirclize

Install conda-forge package:

conda install -c conda-forge pycirclize

API Usage

API usage is described in each of the following sections in the document.

Code Example

1. Circos Plot

from pycirclize import Circos
import numpy as np
np.random.seed(0)

# Initialize Circos sectors
sectors = {"A": 10, "B": 15, "C": 12, "D": 20, "E": 15}
circos = Circos(sectors, space=5)

for sector in circos.sectors:
    # Plot sector name
    sector.text(f"Sector: {sector.name}", r=110, size=15)
    # Create x positions & randomized y values
    x = np.arange(sector.start, sector.end) + 0.5
    y = np.random.randint(0, 100, len(x))
    # Plot line track
    line_track = sector.add_track((80, 100), r_pad_ratio=0.1)
    line_track.xticks_by_interval(interval=1)
    line_track.axis()
    line_track.line(x, y)
    # Plot points track
    points_track = sector.add_track((55, 75), r_pad_ratio=0.1)
    points_track.axis()
    points_track.scatter(x, y)
    # Plot bar track
    bar_track = sector.add_track((30, 50), r_pad_ratio=0.1)
    bar_track.axis()
    bar_track.bar(x, y)

# Plot links 
circos.link(("A", 0, 3), ("B", 15, 12))
circos.link(("B", 0, 3), ("C", 7, 11), color="skyblue")
circos.link(("C", 2, 5), ("E", 15, 12), color="chocolate", direction=1)
circos.link(("D", 3, 5), ("D", 18, 15), color="lime", ec="black", lw=0.5, hatch="//", direction=2)
circos.link(("D", 8, 10), ("E", 2, 8), color="violet", ec="red", lw=1.0, ls="dashed")

circos.savefig("example01.png")

example01.png

2. Chord Diagram

from pycirclize import Circos
import pandas as pd

# Create matrix dataframe (3 x 6)
row_names = ["F1", "F2", "F3"]
col_names = ["T1", "T2", "T3", "T4", "T5", "T6"]
matrix_data = [
    [10, 16, 7, 7, 10, 8],
    [4, 9, 10, 12, 12, 7],
    [17, 13, 7, 4, 20, 4],
]
matrix_df = pd.DataFrame(matrix_data, index=row_names, columns=col_names)

# Initialize Circos from matrix for plotting Chord Diagram
circos = Circos.initialize_from_matrix(
    matrix_df,
    space=5,
    cmap="tab10",
    label_kws=dict(size=12),
    link_kws=dict(ec="black", lw=0.5, direction=1),
)

circos.savefig("example02.png")

example02.png

Not Implemented Features

List of features implemented in other Circos plotting tools but not yet implemented in pyCirclize. I may implement them when I feel like it.

  • Plot histogram
  • Plot boxplot
  • Plot violin
  • Label position auto adjustment

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycirclize-0.2.1.tar.gz (215.4 kB view details)

Uploaded Source

Built Distribution

pycirclize-0.2.1-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

Details for the file pycirclize-0.2.1.tar.gz.

File metadata

  • Download URL: pycirclize-0.2.1.tar.gz
  • Upload date:
  • Size: 215.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.16 Linux/5.15.0-1034-azure

File hashes

Hashes for pycirclize-0.2.1.tar.gz
Algorithm Hash digest
SHA256 318e9d271d5386503d19810443b3e9c0cf2755e6dea9b4955b9c409d543c43dd
MD5 a57e273404380f61220924fb9cd890a6
BLAKE2b-256 45ad67511caa5223e7bc6839c049e6b613e7910546938f465bbeb9b4c5762e6e

See more details on using hashes here.

File details

Details for the file pycirclize-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pycirclize-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.16 Linux/5.15.0-1034-azure

File hashes

Hashes for pycirclize-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 216ff34f8714c2b15758d27d204613a0f9140f8ef486c63a92134de2441928b0
MD5 7fc533274a80d6d2d1f945d1fa1899a2
BLAKE2b-256 db32a1779c61077c7145f75be10ea237faea906a821531f93ff9b4f8ee8c54f2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page