Stem Plot

Horizontal Stem Plot

Categories on Y-axis with horizontal stems.

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

COLORS = {
    'stem': '#3B82F6',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

categories = ['A', 'B', 'C', 'D', 'E', 'F']
values = [75, 85, 60, 90, 70, 82]
y = np.arange(len(categories))

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

for yi, val in zip(y, values):
    ax.plot([0, val], [yi, yi], color=COLORS['stem'], linewidth=2.5, alpha=0.7, zorder=2)
    ax.scatter(val, yi, s=150, c=COLORS['stem'], alpha=0.2, zorder=3)
    ax.scatter(val, yi, s=80, c=COLORS['stem'], edgecolors='white', linewidths=2, zorder=4)

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

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_color(COLORS['grid'])

ax.xaxis.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_yticks(y)
ax.set_yticklabels(categories)
ax.set_xlim(0, 100)
ax.set_xlabel('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