Error Bar Chart

Protein Expression Analysis

Gene expression comparison between control and drug-treated samples showing fold changes with standard error.

Output
Protein Expression Analysis
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Protein expression data
genes = ['TP53', 'BRCA1', 'EGFR', 'MYC', 'KRAS', 'HER2', 'BCL2', 'VEGF']
control = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
treated = np.array([2.5, 0.4, 3.2, 1.8, 0.6, 2.8, 0.3, 4.1])
control_err = np.array([0.15, 0.12, 0.18, 0.14, 0.11, 0.16, 0.13, 0.19])
treated_err = np.array([0.35, 0.08, 0.42, 0.25, 0.09, 0.38, 0.06, 0.55])

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

x = np.arange(len(genes))
width = 0.35

ax.bar(x - width/2, control, width, yerr=control_err, label='Control',
       color='#4927F5', edgecolor='white', capsize=4,
       error_kw={'ecolor': '#a78bfa', 'elinewidth': 1.5, 'capthick': 1.5})
ax.bar(x + width/2, treated, width, yerr=treated_err, label='Drug Treated',
       color='#F5B027', edgecolor='white', capsize=4,
       error_kw={'ecolor': '#fcd34d', 'elinewidth': 1.5, 'capthick': 1.5})

# Significance markers
for i, (c, t) in enumerate(zip(control, treated)):
    if abs(t - c) > 0.5:
        y_max = max(c + control_err[i], t + treated_err[i])
        ax.annotate('*' if abs(t-c) > 1 else '', xy=(i, y_max + 0.15),
                   ha='center', fontsize=14, color='#F5276C', fontweight='bold')

ax.axhline(y=1, color='#666', linestyle='--', linewidth=1, alpha=0.5)
ax.set_xlabel('Gene', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Relative Expression (fold change)', fontsize=11, color='white', fontweight='500')
ax.set_title('Protein Expression: Control vs Drug Treatment', fontsize=14, 
             color='white', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(genes, fontsize=10, fontweight='500')
ax.legend(facecolor='#1a1a2e', edgecolor='#333', labelcolor='white', fontsize=10)
ax.tick_params(colors='#94a3b8', labelsize=9)
ax.set_ylim(0, 5.5)
ax.grid(True, axis='y', alpha=0.2, color='#4a4a6a')
for spine in ax.spines.values():
    spine.set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support