3D Bar Chart

Genomic Variant Calls

Variant detection rates across chromosomes and sequencing depths

Output
Genomic Variant Calls
Python
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import LinearSegmentedColormap

fig = plt.figure(figsize=(12, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d')
ax.set_facecolor('#ffffff')

chroms = 6
depths = 4
xpos = np.arange(chroms)
zpos = np.arange(depths)
xpos, zpos = np.meshgrid(xpos, zpos)
xpos = xpos.flatten()
zpos = zpos.flatten()
ypos = np.zeros_like(xpos)

dx = 0.55
dz = 0.6
np.random.seed(321)
base_rates = [1200, 800, 950, 700, 600, 550]
dy = np.array([base_rates[i % 6] * (1 + zpos[i] * 0.3) + np.random.normal(0, 50) for i in range(24)])

cmap = LinearSegmentedColormap.from_list('neon', ['#276CF5', '#27D3F5', '#6CF527', '#F5D327'])
norm = plt.Normalize(min(dy), max(dy))
colors = [cmap(norm(v)) for v in dy]

ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=colors, alpha=0.85, edgecolor='#e5e7eb', linewidth=0.4)

ax.set_xlabel('Chromosome', fontsize=11, color='#1f2937', labelpad=12)
ax.set_ylabel('Variants', fontsize=11, color='#1f2937', labelpad=12)
ax.set_zlabel('Depth', fontsize=11, color='#1f2937', labelpad=10)
ax.set_title('Genomic Variant Detection Rates', fontsize=14, color='#1f2937', fontweight='bold', pad=20)

ax.set_xticks(range(6))
ax.set_xticklabels(['Chr1', 'Chr2', 'Chr3', 'Chr4', 'Chr5', 'Chr6'], fontsize=8, color='#374151')
ax.set_zticks(range(4))
ax.set_zticklabels(['10x', '30x', '50x', '100x'], fontsize=8, color='#374151')
ax.tick_params(colors='#374151', labelsize=9)

ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#e5e7eb')
ax.yaxis.pane.set_edgecolor('#e5e7eb')
ax.zaxis.pane.set_edgecolor('#e5e7eb')
ax.grid(True, alpha=0.3, linewidth=0.5)

ax.view_init(elev=22, azim=45)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support