Bar Chart
Horizontal Bar Chart
Clean horizontal bars perfect for ranking data
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'bar': '#10B981',
'background': '#FAFBFC',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#E2E8F0',
}
# === DATA ===
categories = ['Product A', 'Product B', 'Product C', 'Product D', 'Product E']
values = [85, 72, 65, 58, 45]
y = 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 ===
bars = ax.barh(y, values, color=COLORS['bar'], height=0.6,
edgecolor='white', linewidth=1)
# Value labels
for i, v in enumerate(values):
ax.text(v + 2, i, str(v), va='center', fontsize=10,
color=COLORS['text'], fontweight='500')
# === AXES ===
ax.set_xlim(0, 100)
ax.set_ylim(-0.5, len(categories) - 0.5)
ax.set_yticks(y)
ax.set_yticklabels(categories)
ax.set_xlabel('Value', fontsize=10, color=COLORS['text_muted'], labelpad=10)
# === 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.xaxis.grid(True, color=COLORS['grid'], linewidth=0.5)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.invert_yaxis()
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Bar Chart examples
☕