Error Bar Chart
Laptop Battery Life Comparison
Battery endurance tests for premium laptops across different usage scenarios.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
laptops = ['MacBook\nPro M3', 'Dell XPS\n15', 'ThinkPad\nX1', 'Surface\nLaptop', 'HP\nSpectre']
web_browsing = np.array([18.5, 12.2, 14.5, 15.2, 11.8])
video = np.array([22.5, 14.8, 16.5, 17.8, 13.5])
productivity = np.array([15.2, 10.5, 12.2, 13.5, 9.8])
web_err = np.array([1.5, 1.2, 1.4, 1.3, 1.0])
video_err = np.array([2.0, 1.5, 1.6, 1.8, 1.2])
prod_err = np.array([1.2, 0.9, 1.1, 1.2, 0.8])
fig, ax = plt.subplots(figsize=(11, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
x = np.arange(len(laptops))
width = 0.25
ax.bar(x - width, web_browsing, width, yerr=web_err, label='Web Browsing',
color='#27D3F5', edgecolor='white', linewidth=1.5, capsize=3,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x, video, width, yerr=video_err, label='Video Playback',
color='#F5276C', edgecolor='white', linewidth=1.5, capsize=3,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x + width, productivity, width, yerr=prod_err, label='Productivity',
color='#6CF527', edgecolor='white', linewidth=1.5, capsize=3,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.axhline(y=10, color='#F5B027', linestyle='--', linewidth=2, alpha=0.7)
ax.set_xlabel('Laptop', fontsize=12, color='#374151', fontweight='600')
ax.set_ylabel('Battery Life (hours)', fontsize=12, color='#374151', fontweight='600')
ax.set_title('Laptop Battery Life Comparison', fontsize=15,
color='#1f2937', fontweight='bold', pad=20)
ax.set_xticks(x)
ax.set_xticklabels(laptops, fontsize=10)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=10)
ax.set_ylim(0, 28)
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
☕