Raincloud Plot

Gene Expression Levels by Cancer Type

Biomarker expression across cancer subtypes

Output
Gene Expression Levels by Cancer Type
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(105)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
COLORS = ['#9C2007', '#F5276C', '#27D3F5']

types = ['Subtype A', 'Subtype B', 'Subtype C']
data = pd.DataFrame({
    'Expression': np.concatenate([
        np.random.lognormal(2.5, 0.8, 90),
        np.random.lognormal(3.2, 0.6, 85),
        np.random.lognormal(2.8, 1.0, 95)
    ]),
    'Type': ['Subtype A']*90 + ['Subtype B']*85 + ['Subtype C']*95
})

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

pt.RainCloud(x='Type', y='Expression', data=data, palette=COLORS,
             bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
             dodge=True, pointplot=False, move=.2)

ax.set_xlabel('Gene Expression (log2)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Cancer Subtype', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Biomarker Expression by Cancer Type', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors='#888', labelsize=10)
for spine in ax.spines.values():
    spine.set_color('#333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support