Stem Plot
Annotated Peak Stem
Highlight and annotate peak value.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'stem': '#6366F1',
'highlight': '#EF4444',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
x = np.arange(1, 11)
y = [35, 42, 38, 55, 48, 72, 65, 58, 62, 70]
highlight_idx = 5 # Peak
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
for i, (xi, yi) in enumerate(zip(x, y)):
color = COLORS['highlight'] if i == highlight_idx else COLORS['stem']
ax.plot([xi, xi], [0, yi], color=color, linewidth=2.5, alpha=0.7, zorder=2)
ax.scatter(xi, yi, s=150 if i == highlight_idx else 100, c=color, alpha=0.2, zorder=3)
ax.scatter(xi, yi, s=80 if i == highlight_idx else 50, c=color,
edgecolors='white', linewidths=2, zorder=4)
# Annotation for peak
ax.annotate(f'Peak: {y[highlight_idx]}', xy=(x[highlight_idx], y[highlight_idx]),
xytext=(x[highlight_idx] + 1.5, y[highlight_idx] + 8),
fontsize=10, fontweight='bold', color=COLORS['highlight'],
arrowprops=dict(arrowstyle='->', color=COLORS['highlight'], lw=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, 12)
ax.set_ylim(0, 90)
ax.set_xlabel('Month', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Value', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Stem Plot examples
☕