Waterfall chart
A waterfall chart starts from an initial total and shows each increase or decrease as a floating bar, ending at the final total. It explains why a number changed.
When to use it
- Explaining a change: budget vs actual, profit bridge, population change.
- The steps are additive.
Ask for it in pltchat
Upload your file and type something like:
"waterfall chart from last year's profit to this year's, green up, red down"
pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.
The matplotlib code
Self-contained with example data; swap in pd.read_csv(...) or
pd.read_excel(...) for your own file.
import numpy as np
import matplotlib.pyplot as plt
steps = {"2023 profit": 120, "Price increase": 35, "New customers": 28,
"Higher costs": -42, "Currency": -11}
labels = list(steps) + ["2024 profit"]
vals = np.array(list(steps.values()))
cum = np.cumsum(vals) # running total after each step
start = np.r_[0, cum[:-1]] # running total before each step
bottoms = np.r_[0, np.minimum(start[1:], cum[1:]), 0]
heights = np.r_[vals[0], np.abs(vals[1:]), cum[-1]]
colors = ["gray"] + ["C2" if v > 0 else "C3" for v in vals[1:]] + ["gray"]
fig, ax = plt.subplots(figsize=(6.4, 4))
ax.bar(labels, heights, bottom=bottoms, color=colors, width=0.6)
for i, (b, h) in enumerate(zip(bottoms, heights)):
ax.text(i, b + h + 2, f"{h:.0f}", ha="center")
ax.set_ylabel("Profit (k$)")
plt.xticks(rotation=20, ha="right")
ax.spines[["top", "right"]].set_visible(False)
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.