Bar Chart

Bar Race Chart

Animated-style market cap ranking visualization.

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

# === STYLE CONFIG ===
COLORS = {
    'bars': ['#EF4444', '#F59E0B', '#10B981', '#3B82F6', '#8B5CF6'],
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
companies = ['Apple', 'Microsoft', 'Google', 'Amazon', 'Meta']
values = [2850, 2780, 1850, 1650, 920]
# Sort by value
sorted_data = sorted(zip(values, companies, COLORS['bars']), reverse=True)
values, companies, colors = zip(*sorted_data)

y = np.arange(len(companies))

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

# === PLOT ===
for i, (val, comp, color) in enumerate(zip(values, companies, colors)):
    # Glow
    ax.barh(i, val, height=0.65, color=color, alpha=0.2, zorder=1)
    # Bar
    ax.barh(i, val, height=0.5, color=color, alpha=0.9,
            edgecolor='white', linewidth=2, zorder=3)

# Labels outside bars to avoid overlap
for i, (val, comp) in enumerate(zip(values, companies)):
    # Company name on y-axis area
    ax.text(-50, i, comp, ha='right', va='center', fontsize=10, 
            fontweight='bold', color=COLORS['text'], zorder=4)
    # Value at end of bar
    ax.text(val + 40, i, f'${val}B', ha='left', va='center', 
            fontsize=10, fontweight='bold', color=COLORS['text'])

# === STYLING ===
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='x', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.tick_params(axis='y', left=False, labelleft=False)

ax.set_xlim(-300, 3400)  # Room for labels on both sides
ax.set_xlabel('Market Cap (Billions USD)', 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