Error Bar Chart

COVID Vaccine Side Effects

Reported side effect rates comparison between COVID-19 vaccine manufacturers.

Output
COVID Vaccine Side Effects
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

side_effects = ['Injection\nSite Pain', 'Fatigue', 'Headache', 'Muscle\nPain', 'Fever', 'Nausea']
pfizer = np.array([84, 62, 55, 38, 14, 12])
moderna = np.array([88, 68, 58, 44, 18, 15])
jj = np.array([48, 38, 38, 32, 9, 14])
err = np.array([5, 6, 5, 4, 3, 3])

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

x = np.arange(len(side_effects))
width = 0.25

ax.bar(x - width, pfizer, width, yerr=err, label='Pfizer-BioNTech',
       color='#27D3F5', edgecolor='white', linewidth=1.5, capsize=3,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x, moderna, width, yerr=err, label='Moderna',
       color='#F5276C', edgecolor='white', linewidth=1.5, capsize=3,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x + width, jj, width, yerr=err, label='Johnson & Johnson',
       color='#F5B027', edgecolor='white', linewidth=1.5, capsize=3,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})

ax.set_xlabel('Side Effect', fontsize=12, color='#374151', fontweight='600')
ax.set_ylabel('Incidence Rate (%)', fontsize=12, color='#374151', fontweight='600')
ax.set_title('COVID-19 Vaccine Side Effects Comparison', fontsize=15, 
             color='#1f2937', fontweight='bold', pad=20)

ax.set_xticks(x)
ax.set_xticklabels(side_effects, fontsize=10)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=10)
ax.set_ylim(0, 100)
ax.grid(True, axis='y', alpha=0.4, color='#e5e7eb')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#d1d5db')
ax.spines['bottom'].set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support