Challenge - 5 Problems
Stacked Area Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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()
Attempts:
2 left
💡 Hint
Stacked area charts fill areas between lines stacked on top of each other.
✗ Incorrect
The plt.stackplot function creates a stacked area chart where each data series is stacked vertically. The labels appear in the legend.
❓ data_output
intermediate1: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]]
Attempts:
2 left
💡 Hint
Each inner list represents one layer in the stacked area chart.
✗ Incorrect
The data list has 4 inner lists, so the stacked area chart will have 4 layers stacked on top of each other.
🔧 Debug
advanced2: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()
Attempts:
2 left
💡 Hint
Check if x and y data lengths match for plotting.
✗ Incorrect
The x list has length 3, but y is a list of 3 lists each of length 2, so y's shape does not match x's length, causing a ValueError.
❓ visualization
advanced1: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()
Attempts:
2 left
💡 Hint
Alpha controls transparency in matplotlib plots.
✗ Incorrect
Setting alpha to 0.5 makes the colors half transparent, so you can see layers beneath or background grid lines.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
The bottom layer's area represents its absolute value over time.
✗ Incorrect
If the bottom layer's area stays the same, its sales did not change. The total stack height increasing means other products' sales increased.