Error Bar Chart
Mattress Sleep Quality Study
Sleep mattress comparison for comfort, support, and temperature regulation.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
mattresses = ['Purple\nHybrid', 'Casper\nOriginal', 'Tempur\nAdapt', 'Saatva\nClassic', 'Helix\nMidnight']
comfort = np.array([88, 85, 92, 90, 86])
support = np.array([85, 82, 95, 92, 88])
cooling = np.array([95, 78, 75, 82, 85])
err = np.array([4, 5, 3, 4, 5])
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
x = np.arange(len(mattresses))
width = 0.25
ax.bar(x - width, comfort, width, yerr=err, label='Comfort',
color='#5314E6', edgecolor='white', linewidth=1.5, capsize=4,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x, support, width, yerr=err, label='Support',
color='#F5276C', edgecolor='white', linewidth=1.5, capsize=4,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x + width, cooling, width, yerr=err, label='Temperature Regulation',
color='#27D3F5', edgecolor='white', linewidth=1.5, capsize=4,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.set_xlabel('Mattress Brand', fontsize=12, color='#374151', fontweight='600')
ax.set_ylabel('Score', fontsize=12, color='#374151', fontweight='600')
ax.set_title('Mattress Sleep Quality Comparison', fontsize=15,
color='#1f2937', fontweight='bold', pad=20)
ax.set_xticks(x)
ax.set_xticklabels(mattresses, fontsize=10)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=10)
ax.set_ylim(60, 102)
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
More Error Bar Chart examples
☕