Bar Chart
Three Group Comparison
Triple grouped bars with error bars.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'group1': '#EF4444',
'group2': '#F59E0B',
'group3': '#10B981',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
categories = ['Week 1', 'Week 2', 'Week 3', 'Week 4']
g1 = [25, 35, 45, 55]
g2 = [30, 40, 35, 50]
g3 = [20, 30, 50, 60]
e1, e2, e3 = [3, 4, 5, 4], [4, 3, 4, 5], [3, 4, 4, 5]
x = np.arange(len(categories))
width = 0.25
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
for offset, vals, errs, color, label in [
(-width, g1, e1, COLORS['group1'], 'Group A'),
(0, g2, e2, COLORS['group2'], 'Group B'),
(width, g3, e3, COLORS['group3'], 'Group C'),
]:
ax.bar(x + offset, vals, width*0.9, color=color, alpha=0.85,
edgecolor='white', linewidth=1.5, label=label, zorder=3)
ax.errorbar(x + offset, vals, yerr=errs, fmt='none', ecolor=COLORS['text'],
elinewidth=1.5, capsize=3, capthick=1.5, zorder=4)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_color(COLORS['grid'])
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=1, zorder=0)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_xticks(x)
ax.set_xticklabels(categories)
ax.set_ylim(0, 80)
ax.set_ylabel('Value', fontsize=10, color=COLORS['text'], labelpad=10)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
ncol=3, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Bar Chart examples
☕