0
0
Matplotlibdata~10 mins

Waterfall chart pattern in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the matplotlib pyplot module with the common alias.

Matplotlib
import matplotlib.[1] as plt
Drag options to blanks, or click blank then click option'
Apyplot
Bplot
Ccharts
Dgraph
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' instead of 'pyplot' causes an import error.
Using 'charts' or 'graph' are not valid matplotlib modules.
2fill in blank
medium

Complete the code to create a list of values representing changes for the waterfall chart.

Matplotlib
changes = [100, -30, 20, [1], -10]
Drag options to blanks, or click blank then click option'
A0
B50
C-20
D40
Attempts:
3 left
💡 Hint
Common Mistakes
Using a negative number when a positive change is intended.
Using zero which shows no change.
3fill in blank
hard

Fix the error in the code to correctly calculate the cumulative sums for the waterfall chart.

Matplotlib
cumulative = [sum(changes[:[1]]) for i in range(len(changes))]
Drag options to blanks, or click blank then click option'
Ai+1
Blen(changes)
Ci
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'i' excludes the current element from the sum.
Using 'len(changes)' sums the entire list every time.
4fill in blank
hard

Fill both blanks to create a waterfall chart using matplotlib with bars and labels.

Matplotlib
plt.bar(range(len(cumulative)), cumulative, color=[1])
plt.xticks(range(len(labels)), [2])
plt.show()
Drag options to blanks, or click blank then click option'
A'blue'
Blabels
C'green'
Dcumulative
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cumulative' as labels causes an error.
Using a color without quotes causes a syntax error.
5fill in blank
hard

Fill all three blanks to add a title, label y-axis, and set grid lines on the chart.

Matplotlib
plt.title([1])
plt.ylabel([2])
plt.grid([3])
Drag options to blanks, or click blank then click option'
A"Waterfall Chart"
B"Value Change"
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around strings causes errors.
Using False disables grid lines.