Stem Plot

Labeled Stem Plot

Stem chart with value labels above markers.

Output
Labeled Stem Plot
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'stem': '#8B5CF6',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
categories = ['A', 'B', 'C', 'D', 'E', 'F']
values = [85, 72, 90, 65, 78, 82]
x = np.arange(len(categories))

# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

# === PLOT ===
for xi, yi in zip(x, values):
    # Stem
    ax.plot([xi, xi], [0, yi], color=COLORS['stem'], linewidth=2.5, alpha=0.7, zorder=2)
    # Glow
    ax.scatter(xi, yi, s=250, c=COLORS['stem'], alpha=0.15, zorder=3)
    # Marker
    ax.scatter(xi, yi, s=120, c=COLORS['stem'], edgecolors='white', linewidths=2.5, zorder=4)
    # Value label
    ax.text(xi, yi + 5, str(yi), ha='center', va='bottom', fontsize=10, 
            fontweight='bold', color=COLORS['text'])

ax.axhline(0, color=COLORS['text'], linewidth=1, zorder=1)

# === 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=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_xlim(-0.5, len(categories) - 0.5)
ax.set_ylim(0, 110)
ax.set_ylabel('Score', fontsize=10, color=COLORS['text'], labelpad=10)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support