Error Bar Chart

Customer Satisfaction Survey

Year-over-year customer satisfaction comparison with 95% confidence intervals for each category.

Output
Customer Satisfaction Survey
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Survey data with confidence intervals
categories = ['Product\nQuality', 'Customer\nService', 'Value for\nMoney', 'Ease of\nUse', 'Would\nRecommend']
scores_2023 = np.array([4.2, 3.8, 3.5, 4.5, 4.1])
scores_2024 = np.array([4.4, 4.2, 3.9, 4.6, 4.5])
ci_2023 = np.array([0.15, 0.18, 0.20, 0.12, 0.16])
ci_2024 = np.array([0.12, 0.14, 0.17, 0.10, 0.11])

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

x = np.arange(len(categories))

ax.errorbar(x - 0.15, scores_2023, yerr=ci_2023, fmt='s', color='#F54927',
            ecolor='#F54927', elinewidth=2, capsize=6, capthick=2,
            markersize=12, markeredgecolor='white', markeredgewidth=1.5,
            label='2023', alpha=0.9)

ax.errorbar(x + 0.15, scores_2024, yerr=ci_2024, fmt='o', color='#27F5B0',
            ecolor='#27F5B0', elinewidth=2, capsize=6, capthick=2,
            markersize=12, markeredgecolor='white', markeredgewidth=1.5,
            label='2024', alpha=0.9)

# Connect points
for i in range(len(categories)):
    ax.plot([x[i] - 0.15, x[i] + 0.15], [scores_2023[i], scores_2024[i]], 
            '--', color='#666', linewidth=1, alpha=0.5)

ax.set_xlabel('Category', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Average Score (1-5)', fontsize=11, color='white', fontweight='500')
ax.set_title('Customer Satisfaction Survey: Year-over-Year', fontsize=14, 
             color='white', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(categories)
ax.legend(facecolor='#1a1a2e', edgecolor='#333', labelcolor='white', fontsize=10)
ax.tick_params(colors='#94a3b8', labelsize=9)
ax.set_ylim(2.5, 5.2)
ax.grid(True, axis='y', alpha=0.2, color='#4a4a6a')
for spine in ax.spines.values():
    spine.set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support