Stem Plot

Dual Stem Comparison

Side-by-side stems for weekly comparison.

Output
Dual Stem Comparison
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'series1': '#6366F1',
    'series2': '#10B981',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
x = np.arange(1, 8)
y1 = [45, 52, 48, 60, 55, 65, 58]
y2 = [38, 42, 55, 48, 62, 52, 68]

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

# === PLOT ===
offset = 0.15

for xi, (v1, v2) in enumerate(zip(y1, y2), 1):
    # Series 1
    ax.plot([xi - offset, xi - offset], [0, v1], color=COLORS['series1'], 
            linewidth=2, alpha=0.7, zorder=2)
    ax.scatter(xi - offset, v1, s=100, c=COLORS['series1'], alpha=0.2, zorder=3)
    ax.scatter(xi - offset, v1, s=60, c=COLORS['series1'], 
               edgecolors='white', linewidths=2, zorder=4)
    
    # Series 2
    ax.plot([xi + offset, xi + offset], [0, v2], color=COLORS['series2'], 
            linewidth=2, alpha=0.7, zorder=2)
    ax.scatter(xi + offset, v2, s=100, c=COLORS['series2'], alpha=0.2, zorder=3)
    ax.scatter(xi + offset, v2, s=60, c=COLORS['series2'], 
               edgecolors='white', linewidths=2, zorder=4)

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_xlim(0, 8)
ax.set_ylim(0, 80)
ax.set_xticks(x)
ax.set_xticklabels(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])
ax.set_ylabel('Value', fontsize=10, color=COLORS['text'], labelpad=10)

# Legend
ax.scatter([], [], c=COLORS['series1'], s=60, label='This Week', edgecolors='white', linewidths=2)
ax.scatter([], [], c=COLORS['series2'], s=60, label='Last Week', edgecolors='white', linewidths=2)
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

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support