Challenge - 5 Problems
Grouped Bar Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of grouped bar chart code
What will be the height of the first bar in the first group when this code runs?
Matplotlib
import matplotlib.pyplot as plt labels = ['A', 'B', 'C'] values1 = [5, 7, 3] values2 = [6, 2, 4] x = range(len(labels)) width = 0.35 fig, ax = plt.subplots() ax.bar(x, values1, width, label='Group 1') ax.bar([p + width for p in x], values2, width, label='Group 2') plt.show()
Attempts:
2 left
💡 Hint
Look at the values1 list and the first bar plotted.
✗ Incorrect
The first bar in the first group corresponds to the first value in values1, which is 5.
❓ data_output
intermediate1:30remaining
Number of bars in grouped bar chart
How many bars will be displayed in total when this grouped bar chart code runs?
Matplotlib
import matplotlib.pyplot as plt labels = ['X', 'Y', 'Z', 'W'] values1 = [1, 2, 3, 4] values2 = [4, 3, 2, 1] values3 = [2, 3, 4, 5] x = range(len(labels)) width = 0.2 fig, ax = plt.subplots() ax.bar(x, values1, width, label='Set 1') ax.bar([p + width for p in x], values2, width, label='Set 2') ax.bar([p + 2*width for p in x], values3, width, label='Set 3') plt.show()
Attempts:
2 left
💡 Hint
Count bars per group and multiply by number of groups.
✗ Incorrect
There are 4 labels and 3 sets, so total bars = 4 * 3 = 12.
❓ visualization
advanced2:00remaining
Identify the correct grouped bar chart
Which option shows the correct grouped bar chart for these data sets?
Matplotlib
import matplotlib.pyplot as plt labels = ['Jan', 'Feb', 'Mar'] sales_A = [10, 15, 7] sales_B = [12, 9, 14] x = range(len(labels)) width = 0.4 fig, ax = plt.subplots() ax.bar(x, sales_A, width, label='Product A') ax.bar([p + width for p in x], sales_B, width, label='Product B') plt.xticks([p + width/2 for p in x], labels) plt.legend() plt.show()
Attempts:
2 left
💡 Hint
Grouped bars are side by side, not stacked or overlapping.
✗ Incorrect
The code shifts the second set of bars by width, so bars appear side by side with small gaps.
🔧 Debug
advanced1:30remaining
Error in grouped bar chart code
What error will this code produce when run?
Matplotlib
import matplotlib.pyplot as plt labels = ['A', 'B'] values1 = [3, 5, 7] values2 = [2, 4] x = range(len(labels)) width = 0.3 fig, ax = plt.subplots() ax.bar(x, values1, width, label='Set 1') ax.bar([p + width for p in x], values2, width, label='Set 2') plt.show()
Attempts:
2 left
💡 Hint
Check if the lengths of x and values1 match.
✗ Incorrect
values1 has 3 items but x has length 2, causing a ValueError about dimension mismatch.
🚀 Application
expert2:00remaining
Calculate total height per group from grouped bar chart data
Given these grouped bar chart data, what is the total height of bars for label 'C'?
Matplotlib
labels = ['A', 'B', 'C', 'D'] values1 = [4, 5, 6, 7] values2 = [1, 2, 3, 4] values3 = [7, 8, 9, 10]
Attempts:
2 left
💡 Hint
Add the values for label 'C' from all three lists.
✗ Incorrect
For label 'C' (index 2), sum is 6 + 3 + 9 = 18.