0
0
Matplotlibdata~20 mins

Stacked area chart in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stacked Area Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a basic stacked area chart code
What will be the output of this code snippet that creates a stacked area chart using matplotlib?
Matplotlib
import matplotlib.pyplot as plt

labels = ['A', 'B', 'C']
data = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
plt.stackplot(range(3), *data, labels=labels)
plt.legend(loc='upper left')
plt.show()
AA line chart with three lines labeled A, B, and C
BA stacked area chart with three layers increasing from left to right, labeled A, B, and C
CA bar chart with three bars labeled A, B, and C
DA scatter plot with points labeled A, B, and C
Attempts:
2 left
💡 Hint
Stacked area charts fill areas between lines stacked on top of each other.
data_output
intermediate
1:30remaining
Number of layers in stacked area chart
Given the data below used in a stacked area chart, how many layers will the chart have?
Matplotlib
data = [[5, 3, 6, 2], [1, 4, 2, 3], [3, 2, 1, 5], [4, 1, 3, 4]]
A3
B2
C4
D5
Attempts:
2 left
💡 Hint
Each inner list represents one layer in the stacked area chart.
🔧 Debug
advanced
2:00remaining
Identify the error in stacked area chart code
What error will this code raise when trying to plot a stacked area chart?
Matplotlib
import matplotlib.pyplot as plt

x = [0, 1, 2]
y = [[1, 2], [3, 4], [5, 6]]
plt.stackplot(x, *y)
plt.show()
AValueError: x and y must have same length
BIndexError: list index out of range
CTypeError: unhashable type: 'list'
DNo error, chart displays correctly
Attempts:
2 left
💡 Hint
Check if x and y data lengths match for plotting.
visualization
advanced
1:30remaining
Effect of alpha parameter in stacked area chart
What visual effect does setting alpha=0.5 have on a stacked area chart in matplotlib?
Matplotlib
import matplotlib.pyplot as plt

x = [0, 1, 2, 3]
y = [[1, 2, 3, 4], [2, 1, 2, 1]]
plt.stackplot(x, *y, alpha=0.5)
plt.show()
AThe stacked areas become semi-transparent, allowing background or overlapping colors to show through
BThe stacked areas become fully opaque and brighter
CThe stacked areas disappear completely
DThe stacked areas change to dashed outlines without fill
Attempts:
2 left
💡 Hint
Alpha controls transparency in matplotlib plots.
🧠 Conceptual
expert
2:30remaining
Interpreting stacked area chart data trends
In a stacked area chart showing sales of three products over time, if the total height of the stack increases but the bottom layer's area stays the same, what does this indicate?
ASales of the bottom product increased and others decreased
BSales of all products increased equally
CSales of the bottom product decreased while others increased
DSales of the bottom product stayed constant while sales of other products increased
Attempts:
2 left
💡 Hint
The bottom layer's area represents its absolute value over time.