Bar Chart

Grouped Bar Chart

Multi-year comparison with grouped categories.

Output
Grouped Bar Chart
Python
import matplotlib.pyplot as plt
import numpy as np

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

# === DATA ===
categories = ['Q1', 'Q2', 'Q3', 'Q4']
group1 = [20, 35, 30, 35]
group2 = [25, 32, 34, 20]
group3 = [18, 28, 25, 30]

x = np.arange(len(categories))
width = 0.25

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

# === PLOT ===
for offset, values, color, label in [
    (-width, group1, COLORS['group1'], '2022'),
    (0, group2, COLORS['group2'], '2023'),
    (width, group3, COLORS['group3'], '2024'),
]:
    bars = ax.bar(x + offset, values, width*0.9, color=color, alpha=0.85,
                  edgecolor='white', linewidth=1.5, label=label, zorder=3)

# === 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_ylabel('Revenue ($M)', fontsize=10, color=COLORS['text'], labelpad=10)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
          ncol=3, 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