Event Plot
Gene Activation Events
Temporal gene expression patterns in cancer research
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Simulate gene activation events
np.random.seed(42)
genes = ['TP53', 'BRCA1', 'MYC', 'EGFR', 'KRAS', 'PIK3CA', 'PTEN']
activation_times = [
np.sort(np.random.exponential(2, 25).cumsum()),
np.sort(np.random.exponential(3, 18).cumsum()),
np.sort(np.random.exponential(1.5, 35).cumsum()),
np.sort(np.random.exponential(2.5, 20).cumsum()),
np.sort(np.random.exponential(1.8, 30).cumsum()),
np.sort(np.random.exponential(2.2, 22).cumsum()),
np.sort(np.random.exponential(4, 12).cumsum()),
]
# Gene type colors (oncogenes red, tumor suppressors blue)
colors = ['#3B82F6', '#3B82F6', '#EF4444', '#EF4444', '#EF4444', '#EF4444', '#3B82F6']
# Create figure
fig, ax = plt.subplots(figsize=(12, 7), facecolor='white')
for i, (times, color) in enumerate(zip(activation_times, colors)):
ax.eventplot(times, lineoffsets=i, linelengths=0.6, linewidths=1.8,
colors=color, alpha=0.75)
# Treatment window
ax.axvspan(20, 35, color='#DCFCE7', alpha=0.5, zorder=0)
ax.text(27.5, 6.7, 'Treatment Window', ha='center', fontsize=10,
color='#16A34A', fontweight='500')
# Gene type labels
for i, color in enumerate(colors):
label = 'TSG' if color == '#3B82F6' else 'ONC'
ax.text(-3, i, label, fontsize=8, va='center', ha='right',
color=color, fontweight='bold')
# Styling
ax.set_yticks(range(len(genes)))
ax.set_yticklabels(genes, fontsize=11, fontweight='700', family='monospace')
ax.set_xlabel('Time (hours)', fontsize=12, fontweight='500', color='#374151')
ax.set_xlim(-5, 60)
ax.set_ylim(-0.5, len(genes) - 0.5)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#E5E7EB')
ax.spines['bottom'].set_color('#E5E7EB')
ax.tick_params(colors='#6B7280', labelsize=10)
ax.xaxis.grid(True, linestyle='--', alpha=0.3, color='#D1D5DB')
# Legend
ax.scatter([], [], c='#3B82F6', s=50, label='Tumor Suppressor', marker='s')
ax.scatter([], [], c='#EF4444', s=50, label='Oncogene', marker='s')
ax.legend(loc='upper right', frameon=True, fontsize=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Event Plot examples
☕