Error Bar Chart

Vaccine Efficacy by Age Group

COVID-19 vaccine efficacy across age groups with 95% confidence intervals on light background.

Output
Vaccine Efficacy by Age Group
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Vaccine efficacy data
age_groups = ['18-29', '30-39', '40-49', '50-59', '60-69', '70+']
efficacy = np.array([95.2, 94.8, 93.5, 91.2, 88.5, 82.3])
ci_lower = np.array([3.2, 3.5, 4.0, 4.5, 5.2, 6.8])
ci_upper = np.array([2.8, 3.0, 3.5, 4.0, 4.8, 6.2])

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

x = np.arange(len(age_groups))
colors = ['#4927F5', '#276CF5', '#27D3F5', '#27F5B0', '#6CF527', '#F5B027']

ax.bar(x, efficacy, yerr=[ci_lower, ci_upper], capsize=6, 
       color=colors, edgecolor='#1f2937', linewidth=0.8,
       error_kw={'ecolor': '#374151', 'elinewidth': 2, 'capthick': 2},
       alpha=0.9, width=0.65)

ax.axhline(y=90, color='#F5276C', linestyle='--', linewidth=1.5, 
           label='90% Threshold', alpha=0.7)

for i, (eff, err) in enumerate(zip(efficacy, ci_upper)):
    ax.text(i, eff + err + 1.5, f'{eff:.1f}%', ha='center', 
            color='#374151', fontsize=10, fontweight='600')

ax.set_xlabel('Age Group', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Vaccine Efficacy (%)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('COVID-19 Vaccine Efficacy by Age Group', fontsize=14, 
             color='#1f2937', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(age_groups)
ax.legend(facecolor='#f8fafc', edgecolor='#d1d5db', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=9)
ax.set_ylim(70, 105)
ax.grid(True, axis='y', alpha=0.3, color='#d1d5db')
for spine in ax.spines.values():
    spine.set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support