Challenge - 5 Problems
Bar Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What does this bar chart code output?
Look at this Python code using matplotlib. What will the bar chart show?
Matplotlib
import matplotlib.pyplot as plt categories = ['Apples', 'Bananas', 'Cherries'] values = [10, 15, 7] plt.bar(categories, values) plt.show()
Attempts:
2 left
💡 Hint
plt.bar can take category names as x values to label bars.
✗ Incorrect
The plt.bar function creates vertical bars. The categories list labels each bar on the x-axis. The values list sets the height of each bar.
❓ data_output
intermediate1:30remaining
How many bars are shown in this chart?
Given this code, how many bars will appear in the bar chart?
Matplotlib
import matplotlib.pyplot as plt fruits = ['Apple', 'Banana', 'Cherry', 'Date'] counts = [5, 8, 2, 6] plt.bar(fruits, counts) plt.show()
Attempts:
2 left
💡 Hint
Each category in the list gets one bar.
✗ Incorrect
There are 4 categories in the fruits list, so 4 bars will be drawn.
❓ visualization
advanced3:00remaining
Which option shows a grouped bar chart comparing two categories?
You want to compare sales of two products across three months using a grouped bar chart. Which code snippet creates this correctly?
Attempts:
2 left
💡 Hint
Use numpy to shift bars left and right for grouping.
✗ Incorrect
Option A correctly shifts bars left and right using numpy's arange and width to create grouped bars. Other options either overlap bars or use wrong plot types.
🧠 Conceptual
advanced1:30remaining
Why are bar charts good for comparing categories?
Which reason best explains why bar charts are used to compare categories?
Attempts:
2 left
💡 Hint
Think about how our eyes compare lengths.
✗ Incorrect
Bar charts use the length of bars to let us quickly see which categories are bigger or smaller, making comparisons easy.
🔧 Debug
expert2:00remaining
What error does this bar chart code raise?
This code tries to plot a bar chart but fails. What error will it raise?
Matplotlib
import matplotlib.pyplot as plt categories = ['A', 'B', 'C'] values = [5, 10] plt.bar(categories, values) plt.show()
Attempts:
2 left
💡 Hint
Check if the categories and values lists have the same length.
✗ Incorrect
The categories list has 3 items but values has only 2. Matplotlib requires both lists to be the same length to match bars to labels.