0
0
Matplotlibdata~20 mins

Why categorical visualization matters in Matplotlib - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Categorical Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this bar chart code?
Look at the code below that creates a bar chart for fruit counts. What will the heights of the bars be?
Matplotlib
import matplotlib.pyplot as plt
fruits = ['Apple', 'Banana', 'Cherry']
counts = [10, 15, 7]
plt.bar(fruits, counts)
plt.show()
ABars with heights 10, 7, and 15 for Apple, Banana, and Cherry respectively
BBars with heights 7, 10, and 15 for Apple, Banana, and Cherry respectively
CBars with heights 15, 10, and 7 for Apple, Banana, and Cherry respectively
DBars with heights 10, 15, and 7 for Apple, Banana, and Cherry respectively
Attempts:
2 left
💡 Hint
Check the order of the counts list and how it matches the fruits list.
data_output
intermediate
1:30remaining
How many categories are shown in this pie chart?
Given this pie chart code, how many slices (categories) will appear?
Matplotlib
import matplotlib.pyplot as plt
labels = ['Red', 'Blue', 'Green', 'Yellow']
sizes = [20, 30, 25, 25]
plt.pie(sizes, labels=labels)
plt.show()
A2
B4
C5
D3
Attempts:
2 left
💡 Hint
Count the number of labels provided.
visualization
advanced
2:30remaining
Which option produces a correct stacked bar chart?
You want to show sales of two products over three months stacked in one bar per month. Which code produces the correct stacked bar chart?
Matplotlib
import matplotlib.pyplot as plt
months = ['Jan', 'Feb', 'Mar']
sales_A = [5, 7, 6]
sales_B = [3, 4, 5]
A
plt.bar(months, sales_A)
plt.bar(months, sales_B)
plt.show()
B
plt.bar(months, sales_A + sales_B)
plt.show()
C
plt.bar(months, sales_A)
plt.bar(months, sales_B, bottom=sales_A)
plt.show()
D
plt.bar(months, sales_B, bottom=sales_A)
plt.bar(months, sales_A)
plt.show()
Attempts:
2 left
💡 Hint
Stacked bars need the bottom parameter to stack the second bar on top of the first.
🧠 Conceptual
advanced
1:30remaining
Why is categorical visualization important in data science?
Which option best explains why visualizing categorical data helps in data science?
AIt helps to quickly compare groups and see patterns or differences between categories.
BIt is only useful for numerical data and does not apply to categories.
CIt replaces the need for any statistical analysis.
DIt makes data look colorful but does not add understanding.
Attempts:
2 left
💡 Hint
Think about how charts help us understand group differences.
🔧 Debug
expert
2:00remaining
What error does this 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 = [10, 20]
plt.bar(categories, values)
plt.show()
AValueError: x and height must have the same size
BTypeError: unsupported operand type(s) for +: 'list' and 'int'
CSyntaxError: invalid syntax
DIndexError: list index out of range
Attempts:
2 left
💡 Hint
Check if the categories and values lists have the same length.