Stem Plot
Multi-Series Stem
Three series comparison with offset stems.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'series': ['#6366F1', '#10B981', '#F59E0B'],
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
x = np.arange(1, 7)
series = [
[5, 7, 4, 8, 6, 9],
[4, 5, 6, 5, 7, 6],
[3, 4, 5, 4, 5, 4],
]
labels = ['High', 'Medium', 'Low']
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
offsets = [-0.2, 0, 0.2]
for s, offset, color, label in zip(series, offsets, COLORS['series'], labels):
for xi, yi in zip(x, s):
ax.plot([xi + offset, xi + offset], [0, yi], color=color, linewidth=2, alpha=0.7, zorder=2)
ax.scatter(xi + offset, yi, s=80, c=color, alpha=0.2, zorder=3)
ax.scatter(xi + offset, yi, s=40, c=color, edgecolors='white', linewidths=1.5, zorder=4)
ax.scatter([], [], c=color, s=40, label=label, edgecolors='white', linewidths=1.5)
ax.axhline(0, color=COLORS['text'], linewidth=1, zorder=1)
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_xlim(0, 7)
ax.set_ylim(0, 11)
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 Stem Plot examples
☕