Error Bar Chart

Reaction Time by Age Group

Cognitive study showing reaction time decline with age for visual and auditory stimuli.

Output
Reaction Time by Age Group
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Reaction time data
age_groups = ['18-25', '26-35', '36-45', '46-55', '56-65', '65+']
visual_rt = np.array([215, 225, 245, 268, 295, 335])
auditory_rt = np.array([180, 188, 205, 225, 250, 285])
visual_err = np.array([18, 20, 22, 25, 30, 38])
auditory_err = np.array([15, 16, 18, 22, 28, 35])

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

x = np.arange(len(age_groups))

ax.errorbar(x, visual_rt, yerr=visual_err, fmt='o-', color='#4927F5',
            ecolor='#4927F5', elinewidth=2, capsize=5, markersize=10,
            markeredgecolor='#1f2937', linewidth=2.5, label='Visual Stimulus', alpha=0.9)
ax.fill_between(x, visual_rt - visual_err, visual_rt + visual_err, 
                color='#4927F5', alpha=0.15)

ax.errorbar(x, auditory_rt, yerr=auditory_err, fmt='s-', color='#F5276C',
            ecolor='#F5276C', elinewidth=2, capsize=5, markersize=9,
            markeredgecolor='#1f2937', linewidth=2.5, label='Auditory Stimulus', alpha=0.9)
ax.fill_between(x, auditory_rt - auditory_err, auditory_rt + auditory_err, 
                color='#F5276C', alpha=0.15)

ax.set_xlabel('Age Group', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Reaction Time (ms)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Reaction Time by Age and Stimulus Type', 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(140, 400)
ax.grid(True, 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