Error Bar Chart
Smartphone Battery Life Comparison
Battery endurance tests for smartphones across different usage scenarios with measurement variability.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
# Battery test data
devices = ['iPhone 15\nPro', 'Samsung\nS24 Ultra', 'Pixel 8\nPro', 'OnePlus\n12', 'Xiaomi\n14 Pro']
screen_on = np.array([9.2, 10.5, 8.8, 11.2, 10.8])
video = np.array([18.5, 21.2, 17.8, 20.5, 19.8])
gaming = np.array([5.8, 6.5, 5.2, 6.8, 6.2])
screen_err = np.array([0.4, 0.5, 0.3, 0.6, 0.5])
video_err = np.array([0.8, 1.0, 0.7, 0.9, 0.8])
gaming_err = np.array([0.3, 0.4, 0.3, 0.4, 0.3])
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
x = np.arange(len(devices))
width = 0.25
bars1 = ax.bar(x - width, screen_on, width, yerr=screen_err, label='Screen-On Time',
color='#27D3F5', edgecolor='white', capsize=3,
error_kw={'ecolor': 'white', 'elinewidth': 1.5})
bars2 = ax.bar(x, video, width, yerr=video_err, label='Video Playback',
color='#6CF527', edgecolor='white', capsize=3,
error_kw={'ecolor': 'white', 'elinewidth': 1.5})
bars3 = ax.bar(x + width, gaming, width, yerr=gaming_err, label='Gaming',
color='#F5276C', edgecolor='white', capsize=3,
error_kw={'ecolor': 'white', 'elinewidth': 1.5})
ax.set_xlabel('Device', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Battery Life (hours)', fontsize=11, color='white', fontweight='500')
ax.set_title('Smartphone Battery Life Comparison', fontsize=14,
color='white', fontweight='bold', pad=15)
ax.set_xticks(x)
ax.set_xticklabels(devices)
ax.legend(facecolor='#1a1a2e', edgecolor='#333', labelcolor='white', fontsize=9)
ax.tick_params(colors='#94a3b8', labelsize=9)
ax.set_ylim(0, 25)
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
More Error Bar Chart examples
☕