Waterfall Chart
Budget Variance Analysis
Light-themed waterfall chart showing budget vs actual variance across different expense categories.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Patch
# Budget variance (in thousands)
categories = ['Original\nBudget', 'Revenue\nOverperform', 'Cost\nSavings', 'Scope\nChanges',
'Delays', 'Currency\nImpact', 'Contingency\nUsed', 'Final\nActual']
values = [0, 45, 28, -35, -22, -8, -15, 0]
# Calculate running total
initial = 500
running_total = initial
bottoms = []
heights = []
colors = []
for i, (cat, val) in enumerate(zip(categories, values)):
if cat == 'Original\nBudget':
bottoms.append(0)
heights.append(initial)
colors.append('#3b82f6')
elif cat == 'Final\nActual':
bottoms.append(0)
heights.append(running_total)
colors.append('#22c55e' if running_total <= initial else '#ef4444')
elif val > 0:
bottoms.append(running_total)
heights.append(val)
colors.append('#22c55e')
running_total += val
else:
bottoms.append(running_total + val)
heights.append(abs(val))
colors.append('#ef4444')
running_total += val
# Create figure with light theme
fig, ax = plt.subplots(figsize=(14, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
x = np.arange(len(categories))
bars = ax.bar(x, heights, bottom=bottoms, color=colors, width=0.65, edgecolor='#e5e7eb', linewidth=1)
# Add value labels
for i, (bar, val, bot, height) in enumerate(zip(bars, values, bottoms, heights)):
y_pos = bot + height / 2
if categories[i] in ['Original\nBudget', 'Final\nActual']:
label = f"${height}K"
ax.text(bar.get_x() + bar.get_width()/2, y_pos, label,
ha='center', va='center', fontsize=10, fontweight='bold', color='white')
else:
label = f"+${val}K" if val > 0 else f"-${abs(val)}K"
ax.text(bar.get_x() + bar.get_width()/2, y_pos, label,
ha='center', va='center', fontsize=9, fontweight='bold', color='white')
# Connect bars
for i in range(len(x) - 1):
if i == 0:
y = initial
else:
y = bottoms[i] + heights[i]
ax.plot([x[i] + 0.35, x[i+1] - 0.35], [y, y],
color='#9ca3af', linestyle='--', linewidth=1.5, alpha=0.7)
# Styling
ax.set_xlim(-0.6, len(categories) - 0.4)
ax.set_ylim(0, max(bottoms[i] + heights[i] for i in range(len(heights))) * 1.1)
ax.set_xticks(x)
ax.set_xticklabels(categories, fontsize=9, color='#374151')
ax.set_ylabel('Budget ($ Thousands)', fontsize=12, color='#374151', fontweight='500')
ax.set_title('Project Budget Variance Analysis', fontsize=16, color='#111827', fontweight='bold', pad=20)
ax.tick_params(axis='y', colors='#374151', labelsize=10)
ax.yaxis.grid(True, linestyle='--', alpha=0.4, color='#e5e7eb')
ax.set_axisbelow(True)
for spine in ax.spines.values():
spine.set_color('#d1d5db')
# Legend outside plot
legend_elements = [
Patch(facecolor='#3b82f6', label='Original Budget'),
Patch(facecolor='#22c55e', label='Favorable Variance'),
Patch(facecolor='#ef4444', label='Unfavorable Variance'),
Patch(facecolor='#22c55e', edgecolor='#166534', linewidth=2, label='Final Actual')
]
ax.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, -0.12),
ncol=4, fontsize=9, facecolor='white', edgecolor='#d1d5db', labelcolor='#374151')
plt.tight_layout()
plt.subplots_adjust(bottom=0.18)
plt.show()
Library
Matplotlib
Category
Financial
More Waterfall Chart examples
☕