Line & Scatter
Grouped Error Bars
Multiple series comparison with error bars side by side.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'group_a': '#6366F1',
'group_b': '#10B981',
'background': '#FAFBFC',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#E2E8F0',
}
# === DATA ===
categories = ['Q1', 'Q2', 'Q3', 'Q4']
x = np.arange(len(categories))
width = 0.35
group_a = [4.2, 5.1, 4.8, 5.5]
group_a_err = [0.4, 0.5, 0.3, 0.6]
group_b = [3.8, 4.5, 5.2, 5.0]
group_b_err = [0.3, 0.4, 0.5, 0.4]
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
ax.errorbar(x - width/2, group_a, yerr=group_a_err, fmt='o',
color=COLORS['group_a'], ecolor=COLORS['group_a'],
elinewidth=2, capsize=6, capthick=2, markersize=12,
markeredgecolor='white', markeredgewidth=2, label='Group A')
ax.errorbar(x + width/2, group_b, yerr=group_b_err, fmt='s',
color=COLORS['group_b'], ecolor=COLORS['group_b'],
elinewidth=2, capsize=6, capthick=2, markersize=12,
markeredgecolor='white', markeredgewidth=2, label='Group B')
# === AXES ===
ax.set_xlim(-0.5, len(categories) - 0.5)
ax.set_ylim(0, 7)
ax.set_xticks(x)
ax.set_xticklabels(categories)
ax.set_ylabel('Value', fontsize=10, color=COLORS['text_muted'], labelpad=10)
# === STYLING ===
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=0.5, alpha=0.7)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
ncol=2, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Line & Scatter examples
☕