Waterfall Chart

Cost of Quality Analysis

Quality cost waterfall showing prevention, appraisal, and failure costs.

Output
Cost of Quality Analysis
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Patch

categories = ['Total\nRevenue', 'Prevention\nCosts', 'Appraisal\nCosts', 'Internal\nFailures', 
              'External\nFailures', 'Warranty\nClaims', 'Quality\nProfit Impact']
values = [0, -45, -32, -28, -65, -42, 0]

initial = 1000
running_total = initial
bottoms, heights, colors = [], [], []

palette = ['#22c55e', '#3b82f6', '#f59e0b', '#ef4444', '#dc2626']

for i, (cat, val) in enumerate(zip(categories, values)):
    if 'Total' in cat:
        bottoms.append(0)
        heights.append(initial)
        colors.append('#3b82f6')
    elif 'Quality' in cat:
        bottoms.append(0)
        heights.append(running_total)
        colors.append('#22c55e')
    else:
        bottoms.append(running_total + val)
        heights.append(abs(val))
        colors.append(palette[(i-1) % len(palette)])
        running_total += val

fig, ax = plt.subplots(figsize=(12, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

x = np.arange(len(categories))
bars = ax.bar(x, heights, bottom=bottoms, color=colors, width=0.6, edgecolor='#e5e7eb', linewidth=1)

for i, (bar, val, bot, height) in enumerate(zip(bars, values, bottoms, heights)):
    y_pos = bot + height / 2
    if 'Total' in categories[i] or 'Quality' in categories[i]:
        label = f"${height}M"
        ax.text(bar.get_x() + bar.get_width()/2, y_pos, label, ha='center', va='center', 
                fontsize=11, fontweight='bold', color='white')
    else:
        label = f"${abs(val)}M"
        ax.text(bar.get_x() + bar.get_width()/2, y_pos, label, ha='center', va='center', 
                fontsize=10, fontweight='bold', color='white')

for i in range(len(x) - 1):
    y = initial if i == 0 else bottoms[i]
    ax.plot([x[i] + 0.35, x[i+1] - 0.35], [y, y], color='#9ca3af', linestyle='--', linewidth=1.5, alpha=0.7)

ax.set_xlim(-0.6, len(categories) - 0.4)
ax.set_ylim(0, initial * 1.1)
ax.set_xticks(x)
ax.set_xticklabels(categories, fontsize=9, color='#374151')
ax.set_ylabel('Revenue Impact ($ Millions)', fontsize=12, color='#374151', fontweight='500')
ax.set_title('Cost of Quality Impact on Revenue', 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')

coq = initial - running_total
coq_pct = (coq / initial) * 100
ax.annotate(f'Total Cost of Quality: ${coq}M ({coq_pct:.1f}% of revenue)', xy=(0.98, 0.95), xycoords='axes fraction',
            fontsize=10, color='#dc2626', ha='right', fontweight='bold',
            bbox=dict(boxstyle='round,pad=0.4', facecolor='#fef2f2', edgecolor='#ef4444'))

legend_elements = [Patch(facecolor='#3b82f6', label='Revenue'), Patch(facecolor='#22c55e', label='Prevention'),
                   Patch(facecolor='#f59e0b', label='Appraisal'), Patch(facecolor='#ef4444', label='Failure Costs')]
ax.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, -0.1), ncol=4, fontsize=9,
          facecolor='white', edgecolor='#d1d5db', labelcolor='#374151')

plt.tight_layout()
plt.subplots_adjust(bottom=0.15)
plt.show()
Library

Matplotlib

Category

Financial

Did this help you?

Support PyLucid to keep it free & growing

Support