Bar Chart

Grouped Bar Comparison

Grouped bars comparing multiple metrics

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

np.random.seed(42)

categories = ['Q1', 'Q2', 'Q3', 'Q4']
group1 = [45, 52, 48, 61]
group2 = [38, 45, 55, 58]
group3 = [42, 48, 51, 54]

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

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

bars1 = ax.bar(x - width, group1, width, label='2022', color='#F5276C', edgecolor='none')
bars2 = ax.bar(x, group2, width, label='2023', color='#27D3F5', edgecolor='none')
bars3 = ax.bar(x + width, group3, width, label='2024', color='#6CF527', edgecolor='none')

for bars in [bars1, bars2, bars3]:
    for bar in bars:
        height = bar.get_height()
        ax.text(bar.get_x() + bar.get_width()/2., height + 1, f'{int(height)}',
                ha='center', va='bottom', color='white', fontsize=8)

ax.set_xticks(x)
ax.set_xticklabels(categories, color='white', fontsize=11)
ax.set_ylabel('Revenue (M)', color='#888888', fontsize=11)
ax.set_ylim(0, 75)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#333333')
ax.spines['bottom'].set_color('#333333')
ax.tick_params(axis='both', colors='#888888', labelsize=9)
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_axisbelow(True)

ax.legend(loc='upper left', frameon=False, labelcolor='white', fontsize=9)
ax.set_title('Quarterly Revenue Comparison', color='white', fontsize=14, fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support