How To Create A Waterfall Chart In Python Using Plotly & Excel
In this tutorial, I will show you, how to create a Waterfall Chart, also known as a Bridge Chart, in Python & Excel by using the library called Plotly. The data is coming directly from an excel file.
You can do all the changes in the excel file and after running the script again you will have your updated chart.
The Waterfall Chart is also interactive. If you hover over the chart, you will see additional information. The final chart will be also saved in an HTML file. Hence, you could also send the chart to your friends & colleagues, who do not even need to have Python installed on their machines.
This tutorial is focusing on beginners in Python. Even you have never written a single line of code in Python, you will be able to have your waterfall chart by the end of this tutorial.
# Imports import plotly.graph_objects as go import plotly import pandas as pd import sys import os os.chdir(sys.path[0]) # Read Excel Data and store it in a variable: df [dataframe] df = pd.read_excel('data.xlsx') # Store values of columns in a seperate variable x = df['Category'] y = df['Value'] measure = df['Measure'] text = df['Text'] # Create Waterfall Chart fig = go.Figure(go.Waterfall( measure = measure, x = x, y = y, text = text, textposition = 'outside' )) # Update Layout [OPTIONAL] fig.update_layout( title = 'EBIT Development 2018 - 2020 in mio USD', title_font_size = 32, font_size = 16, plot_bgcolor = 'rgba(0,0,0,0)' # Transparent Background ) # Export Waterfall to HTML plotly.offline.plot(fig,filename='Waterfall.html')