Skip to main content

plotlywaterfall

CI PyPI Python versions uv Ruff Examples

Description

A small package adding simple waterfall plotting capabilities on top of the plotly graphing package. Waterfall graphs are useful to display e.g. financial data such as cashflow statements in an easily digestible format.

While plotly includes basic capabilities to plot waterfall graphs, it ships only limited features. The plotlywaterfall package provides simple, plotly-express-style waterfall graphs with grouping, multiple stacked categories and variable colors.

Installation

Requires Python 3.11 or newer.

pip install plotlywaterfall
# or
uv add plotlywaterfall

Usage

Example gallery with interactive charts for every feature (rendered from examples/examples.ipynb by CI).

waterfall(df, x=..., y=..., ...) returns a plotly figure, like plotly express' px.bar. The class Waterfall takes the same arguments (Waterfall(...).get_fig()) and also lets you add subtotals step by step with add_subtotal.

A complete example with groups, stacked categories, a subtotal and a total:

import pandas as pd

from plotlywaterfall import waterfall

df = pd.DataFrame(
    {
        "X": ["A", "B", "C"] * 4 + ["D", "D"],
        "Y": [4, 1, 8, 7, 3, 2] + [i - 1 for i in [4, 1, 8, 7, 3, 2]] + [8, 5],
        "category": ["one"] * 3 + ["two"] * 3 + ["one"] * 3 + ["two"] * 3 + ["two", "three"],
        "group": ["Group1"] * 6 + ["Group2"] * 6 + ["Group2", "Group3"],
    }
)

fig = waterfall(
    df,
    x="X",
    y="Y",
    category="category",
    group="group",
    total=True,
    subtotals={"C": "Subtotal"},
    color_discrete_map={"one": "#2a78d6", "two": "#eb6834", "three": "#1baf7a"},
    pattern_shape="group",
)
fig.update_layout(template="plotly_white")
fig

Example waterfall chart with three groups, stacked categories, a subtotal and a total

Labels, number format and hover

Every bar is labelled with its change (signed, e.g. +9) or, for totals, its value; hovering shows the step, its category and the running total.

Argument Meaning Default
value_labels "bar" (one label per bar, outside), "segment" (inside each stacked segment), "both", or None / False for no labels "bar"
number_format Python format spec for the absolute value (e.g. ",.1f") or a function thousands separators, up to two decimals
number_prefix / number_suffix Units around the number; the sign stays in front (-$5M) ""
title Figure title None
labels Display names for columns, like plotly express ({"Y": "Cashflow [MUSD]"}); titles the axes y-axis titled with the y column
waterfall(df, x="X", y="Y", total=True, number_prefix="$", number_suffix="M",
          title="Cash bridge", labels={"Y": "Cashflow [MUSD]"})

Colors

Colours work like in plotly express:

Argument Meaning
color What drives the colour: the category column, the group column, or "direction" (increase / decrease / total). Default: the category column if given, else the group column, else "direction".
color_discrete_map Colour per value, e.g. {"one": "red"}. (group, category) tuples colour one group's category. With color="direction" the keys are "increase", "decrease", "total" (default green / red / grey). Keys that match no value raise a warning.
color_discrete_sequence Colours for values missing from the map, assigned in order. Default: the colorway of the active plotly template.
pattern_shape The group or category column, to give its values different fill patterns, e.g. colour by category and pattern by group.
pattern_shape_map Pattern per value, e.g. {"Actual": "/"}.

Colours are assigned per value, so a category has the same colour in every group:

waterfall(df, x="X", y="Y", category="category", group="group", total=True,
          pattern_shape="group")

Coming from version 0.9? The colors argument was replaced by color / color_discrete_map; see Upgrading from 0.9.

Mixed signs

Categories of one bar may have different signs, e.g. a subsidy (+1) and a restructuring charge (−4) at the same x-value, or a total that combines positive and negative categories. Such a bar is split into one narrow sub-step per category that walks from the level where the bar starts to where it ends, with a light "net ghost" bar behind it showing the net change:

df = pd.DataFrame({
    "X": ["Revenue", "Costs", "Other", "Other"],
    "Y": [9, -7, 1, -4],
    "category": ["Operating", "Operating", "Operating", "One-off"],
})
waterfall(df, x="X", y="Y", category="category", total=True)

Options:

Argument Values Default
mixed_signs "steps" (split into sub-steps), "error" (raise NotImplementedError, the behaviour before 1.0) "steps"
net_ghost True, False, or a dict of plotly marker properties for the net bar True
step_order "data" (order of the categories in the DataFrame), "positive_first", "largest_first" "data"

Bars whose categories share a sign are drawn as normal stacked bars. With several groups each group's bar walks on its own; with many groups and categories the sub-steps get narrow, so increase barwidth.

Disclaimer

I might maintain and improve the package. I might also not.

Development

The project uses uv for environments and dependency locking.

git clone https://github.com/docdru/plotlywaterfall.git
cd plotlywaterfall
uv sync                       # creates .venv with the package + all dev tools
uv run pre-commit install     # optional: run checks on every commit

Common tasks:

Task Command
Run tests uv run pytest
Tests with coverage uv run pytest --cov
Test another Python uv run --python 3.11 pytest
Lint / auto-fix uv run ruff check --fix
Format uv run ruff format
Type check uv run mypy
Execute example notebook uv run pytest --nbmake examples/ -p no:warnings
Build the docs site (gallery + README image) uv run --group notebook --with nbconvert --with kaleido python scripts/build_docs.py --out site
Open notebooks uv run --with jupyterlab jupyter lab
Build sdist + wheel uv build

CI (GitHub Actions) runs lint, type checks, the test suite on Python 3.11–3.15 (Linux, plus Windows; macOS on main and the weekly run), a test against the lowest supported dependency versions, the docs site, and a package build.

The docs site job executes examples/examples.ipynb, renders it to HTML with interactive charts and renders the README image from examples/readme_example.py (keep it in sync with the README code). Pull requests get the result as the docs-site artifact of the CI run; on main it is published to GitHub Pages. Nothing generated is committed. One-time setup: Settings → Pages → Build and deployment → Source: GitHub Actions.

AI pull-request review

Pull requests get an automated review comment (correctness and tests, API/docs consistency, security and supply chain, surprising changes) from .github/workflows/ai-review.yml, which runs scripts/ai_review.py against the Mistral API. The comment is updated on every push.

  • Setup: add the repository secret MISTRAL_API_KEY (Settings → Secrets and variables → Actions). Optionally set the repository variable AI_REVIEW_MODEL to override the default model (mistral-large-2512).
  • Scope: runs for non-draft PRs from branches in this repository by authors with write access; fork, bot and draft PRs are skipped. Mark a draft "Ready for review" to trigger it.
  • Try locally (prints the prompt, calls nothing, posts nothing): GITHUB_REPOSITORY=docdru/plotlywaterfall GITHUB_TOKEN=$(gh auth token) python scripts/ai_review.py --pr 1 --dry-run

The review is advisory: it is not part of the required checks, and its findings should be verified.

Releasing

  1. Bump __version__ in src/plotlywaterfall/__about__.py and add a CHANGELOG.md entry.
  2. Commit, then tag and push: git tag v0.9.4 && git push origin v0.9.4.
  3. The Release workflow builds the package and publishes it to PyPI via Trusted Publishing (no API token needed).

Changelog

Refer to CHANGELOG.md

Metadata

Release files for plotlywaterfall 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plotlywaterfall 1.0.0
File Size Uploaded Provenance Actions
plotlywaterfall-1.0.0.tar.gz 30.1 kB With provenance Details for plotlywaterfall-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for plotlywaterfall 1.0.0
File Interpreter ABI Platform Actions
plotlywaterfall-1.0.0-py3-none-any.whl Python 3 none any Details for plotlywaterfall-1.0.0-py3-none-any.whl

Total release size: 48.8 kB

Release files / plotlywaterfall-1.0.0.tar.gz

Download URL plotlywaterfall-1.0.0.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
750ecbb4a664314febf90983de4ebba0a8999744bf3cc97da61e8c0bebdff8c4
BLAKE2b-256 checksum
How to use checksums
944bdc11e001087cff69ef95e9dc1d115ceb9d19c2969ed7dde3222dc90dad67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / plotlywaterfall-1.0.0-py3-none-any.whl

Download URL plotlywaterfall-1.0.0-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b530e7e70eca0ede28759c222fb32ce166c3f70e6a7b6c5baed3e7fc0320ee35
BLAKE2b-256 checksum
How to use checksums
bbb7a35ef349307670929a8077ffbf28e6d2feac07b82effe132e0fc07688aa5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for plotlywaterfall 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for plotlywaterfall-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page