Bar Chart

Waterfall Chart

Financial waterfall showing incremental changes.

Output
Waterfall Chart
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'increase': '#10B981',
    'decrease': '#EF4444',
    'total': '#6366F1',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

# === DATA ===
categories = ['Start', 'Sales', 'Returns', 'Marketing', 'Costs', 'End']
values = [100, 40, -15, -20, -25, 0]
values[-1] = sum(values[:-1])

# Calculate positions
cumulative = []
running = 0
for i, v in enumerate(values):
    if i == 0:
        cumulative.append(0)
    elif i == len(values) - 1:
        cumulative.append(0)
    else:
        cumulative.append(running)
    running += v

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

# === PLOT ===
for i, (cat, val, bottom) in enumerate(zip(categories, values, cumulative)):
    if i == 0 or i == len(values) - 1:
        color = COLORS['total']
        height = values[-1] if i == len(values) - 1 else val
        b = 0
    else:
        color = COLORS['increase'] if val >= 0 else COLORS['decrease']
        height = abs(val)
        b = bottom if val >= 0 else bottom + val
    
    ax.bar(i, height, bottom=b, width=0.5, color=color, alpha=0.85,
           edgecolor='white', linewidth=2, zorder=3)
    
    # Value label - placed above bars, not overlapping
    if i in [0, len(values)-1]:
        label_y = height + 3
        label_text = str(abs(val)) if i == 0 else str(values[-1])
    else:
        label_y = b + height + 3 if val >= 0 else b - 3
        label_text = f'{val:+d}'
    
    ax.text(i, label_y, label_text, ha='center', va='bottom' if val >= 0 else 'top',
            fontsize=9, fontweight='bold', color=COLORS['text'])

# === 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(range(len(categories)))
ax.set_xticklabels(categories)
ax.set_ylim(-10, 130)  # Extra room for labels
ax.set_ylabel('Value ($K)', 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