0
0
Matplotlibdata~30 mins

Waterfall chart pattern in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Waterfall Chart Pattern
📖 Scenario: Imagine you work in a company and want to show how different factors contribute to the final profit. A waterfall chart helps visualize how each part adds or subtracts from the total.
🎯 Goal: You will create a waterfall chart using matplotlib to display the step-by-step changes in profit.
📋 What You'll Learn
Create a dictionary with exact revenue and cost values
Create a list of labels for the waterfall steps
Calculate the cumulative values for the waterfall bars
Plot the waterfall chart using matplotlib with correct colors and labels
Display the final waterfall chart
💡 Why This Matters
🌍 Real World
Waterfall charts are used in business to show how different factors contribute to a total, such as profit or budget changes.
💼 Career
Data analysts and business intelligence professionals use waterfall charts to communicate financial and operational insights clearly.
Progress0 / 4 steps
1
Create the data dictionary
Create a dictionary called data with these exact entries: 'Sales': 35000, 'Returns': -5000, 'Marketing': -7000, 'Development': -8000, 'Profit': 15000.
Matplotlib
Need a hint?

Use curly braces to create a dictionary with the exact keys and values.

2
Create the labels list
Create a list called labels with these exact strings in order: 'Sales', 'Returns', 'Marketing', 'Development', 'Profit'.
Matplotlib
Need a hint?

Use square brackets to create a list with the exact strings in the given order.

3
Calculate cumulative values for the waterfall
Create a list called values that contains the values from data in the order of labels. Then create a list called cumulative that holds the cumulative sums of values starting with 0.
Matplotlib
Need a hint?

Use a list comprehension to get values in order. Then use a for loop to build cumulative sums starting from zero.

4
Plot and display the waterfall chart
Import matplotlib.pyplot as plt. Use plt.bar to plot the waterfall bars with labels on x-axis and values as heights. Use bottom=cumulative to stack bars. Color positive bars green and negative bars red. Finally, call plt.show() to display the chart.
Matplotlib
Need a hint?

Use plt.bar with bottom=cumulative and color bars green or red based on positive or negative values. Then call plt.show().