How to Create a Waterfall Chart in Python Using Plotly and Excel
The Plotly Waterfall trace shows how a starting value moves to an ending one through a series of gains and losses, here EBIT components read from Excel. It gives you more control over colors, connectors and totals than the Excel chart does, and it exports to an interactive HTML file.

Install the packages
You need Python plus two libraries: plotly draws the chart and pandas reads the Excel file. On Windows, press Windows + R, type cmd and press Enter to open the command prompt, then install plotly:
pip install plotly
Next, install pandas:
pip install pandas
pandas reads .xlsx files through openpyxl, so also run pip install openpyxl. The script below works with pandas 2.3 and 3.1 and Plotly 7.2.
Prepare the Excel data
The workbook holds one row per bar. Column A has the categories for the x-axis and column B the values. For a total or subtotal, such as EBIT 2019, I enter 0, because Plotly calculates the total itself.
Column C tells Plotly how to treat each value: absolute for the starting value, relative for a change and total for a subtotal or total. Column D holds remarks that explain each change; they do not appear in the chart. Column E joins the value and the remark into a label. That column is optional, but in a business report the reason next to each bar saves questions.

Write the script
The script reads the sheet into a DataFrame, passes four columns to go.Waterfall, styles the layout and saves an HTML file. Create a file named waterfall.py and start with the imports:
import plotly.graph_objects as go
import plotly
import pandas as pd
Read the Excel file into a DataFrame called df:
df = pd.read_excel('data.xlsx')
Store each column in its own variable:
x = df['Category']
y = df['Value']
measure = df['Measure']
text = df['Text']
The names must match the column headers in the Excel file exactly, including the capital letters; otherwise pandas raises a KeyError.
Create the waterfall chart:
fig = go.Figure(go.Waterfall(
measure=measure,
x=x,
y=y,
text=text,
textposition='outside'
))
Set the title, font sizes and a transparent plot background:
fig.update_layout(
title='EBIT Development 2018 to 2020 in Million USD',
title_font=dict(size=32),
font=dict(size=16),
plot_bgcolor='rgba(0, 0, 0, 0)'
)
Finally, export the chart to an HTML file:
plotly.offline.plot(fig, filename='waterfall.html')
Run the script
Run the script from the folder it is saved in. In the command prompt, change to that folder with cd:
cd path_to_your_folder
Then run it:
python waterfall.py
The chart opens in your browser. The HTML file stays in the same folder, so you can send it to colleagues who do not have Python installed.

Change colors and connectors
By default Plotly draws increases green, decreases red and totals blue, with thin solid connector lines. Each of the three bar types and the connector can be styled separately inside go.Waterfall, for example to match a corporate palette:
fig = go.Figure(go.Waterfall(
measure=measure,
x=x,
y=y,
text=text,
textposition='outside',
increasing=dict(marker=dict(color='seagreen')),
decreasing=dict(marker=dict(color='firebrick')),
totals=dict(marker=dict(color='steelblue')),
connector=dict(line=dict(color='gray', dash='dot')),
))
Any CSS color name or hex code works. Set connector=dict(visible=False) to remove the lines between the bars.
Going further
To update the chart without opening the command prompt, run the script from Excel with a button. You change the numbers, save the file and click once.
My post on running a Python script from Excel with VBA shows the macro. My waterfall chart template was built that way. The same Excel-to-Plotly steps also give you a treemap or sunburst chart.
Two options need no Python: the free chart maker draws a waterfall chart from pasted cells in the browser, and inside Excel my add-in Deltaline builds bridge charts, from last year’s EBIT to this year’s, linked to your table.
