Error Bar Chart

Antihypertensive Drug Trial

Clinical trial comparing blood pressure reduction between drug and placebo groups over 12 weeks.

Output
Antihypertensive Drug Trial
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Blood pressure data
time_points = ['Baseline', 'Week 2', 'Week 4', 'Week 8', 'Week 12']
systolic_drug = np.array([145, 138, 132, 128, 125])
systolic_placebo = np.array([144, 143, 142, 141, 140])
diastolic_drug = np.array([92, 88, 85, 82, 80])
diastolic_placebo = np.array([91, 90, 90, 89, 89])
sys_err = np.array([5, 4, 4, 3, 3])
dia_err = np.array([3, 3, 2, 2, 2])

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5), facecolor='#0a0a0f')

for ax in [ax1, ax2]:
    ax.set_facecolor('#0a0a0f')

x = np.arange(len(time_points))

# Systolic
ax1.errorbar(x, systolic_drug, yerr=sys_err, fmt='o-', color='#27D3F5',
             ecolor='#27D3F5', elinewidth=2, capsize=5, markersize=10,
             markeredgecolor='white', linewidth=2, label='Drug', alpha=0.9)
ax1.errorbar(x, systolic_placebo, yerr=sys_err, fmt='s--', color='#F5276C',
             ecolor='#F5276C', elinewidth=2, capsize=5, markersize=8,
             markeredgecolor='white', linewidth=2, label='Placebo', alpha=0.9)
ax1.axhline(y=130, color='#6CF527', linestyle=':', linewidth=2, 
            label='Normal (<130)', alpha=0.7)
ax1.fill_between(x, 90, 120, color='#6CF527', alpha=0.1)

ax1.set_xlabel('Time Point', fontsize=11, color='white', fontweight='500')
ax1.set_ylabel('Systolic BP (mmHg)', fontsize=11, color='white', fontweight='500')
ax1.set_title('Systolic Blood Pressure', fontsize=13, color='white', fontweight='bold')
ax1.set_xticks(x)
ax1.set_xticklabels(time_points, rotation=45, ha='right')
ax1.legend(facecolor='#1a1a2e', edgecolor='#333', labelcolor='white', fontsize=9)
ax1.tick_params(colors='#94a3b8', labelsize=9)
ax1.set_ylim(110, 160)
ax1.grid(True, alpha=0.2, color='#4a4a6a')

# Diastolic
ax2.errorbar(x, diastolic_drug, yerr=dia_err, fmt='o-', color='#27D3F5',
             ecolor='#27D3F5', elinewidth=2, capsize=5, markersize=10,
             markeredgecolor='white', linewidth=2, label='Drug', alpha=0.9)
ax2.errorbar(x, diastolic_placebo, yerr=dia_err, fmt='s--', color='#F5276C',
             ecolor='#F5276C', elinewidth=2, capsize=5, markersize=8,
             markeredgecolor='white', linewidth=2, label='Placebo', alpha=0.9)
ax2.axhline(y=80, color='#6CF527', linestyle=':', linewidth=2, 
            label='Normal (<80)', alpha=0.7)
ax2.fill_between(x, 60, 80, color='#6CF527', alpha=0.1)

ax2.set_xlabel('Time Point', fontsize=11, color='white', fontweight='500')
ax2.set_ylabel('Diastolic BP (mmHg)', fontsize=11, color='white', fontweight='500')
ax2.set_title('Diastolic Blood Pressure', fontsize=13, color='white', fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(time_points, rotation=45, ha='right')
ax2.legend(facecolor='#1a1a2e', edgecolor='#333', labelcolor='white', fontsize=9)
ax2.tick_params(colors='#94a3b8', labelsize=9)
ax2.set_ylim(70, 100)
ax2.grid(True, alpha=0.2, color='#4a4a6a')

for ax in [ax1, ax2]:
    for spine in ax.spines.values():
        spine.set_color('#333333')

plt.suptitle('Antihypertensive Drug Trial Results', fontsize=14, 
             color='white', fontweight='bold', y=1.02)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support