0
0
Matplotlibdata~20 mins

Why pie charts show proportions in Matplotlib - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pie Chart Proportions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why do pie charts represent proportions?

Pie charts are often used to show parts of a whole. Why do pie charts represent proportions correctly?

ABecause pie charts only show the largest category and ignore smaller ones.
BBecause pie charts use colors to show different categories without size differences.
CBecause each slice's angle is proportional to its value relative to the total sum.
DBecause pie charts display data points as separate bars side by side.
Attempts:
2 left
💡 Hint

Think about how the size of each slice relates to the total data.

Predict Output
intermediate
1:30remaining
Output of pie chart slice sizes

Given the data [10, 20, 30], what are the angles in degrees of the pie chart slices?

Matplotlib
data = [10, 20, 30]
total = sum(data)
angles = [(x / total) * 360 for x in data]
print(angles)
A[100.0, 200.0, 300.0]
B[60.0, 120.0, 180.0]
C[10.0, 20.0, 30.0]
D[120.0, 60.0, 180.0]
Attempts:
2 left
💡 Hint

Calculate each value's fraction of the total, then multiply by 360.

data_output
advanced
2:00remaining
Calculate proportions from raw data

Given a list of sales numbers [50, 150, 300], calculate the proportion of each category as decimals rounded to two places.

Matplotlib
sales = [50, 150, 300]
total_sales = sum(sales)
proportions = [round(x / total_sales, 2) for x in sales]
print(proportions)
A[0.12, 0.36, 0.72]
B[0.11, 0.33, 0.56]
C[0.17, 0.50, 1.0]
D[0.10, 0.30, 0.60]
Attempts:
2 left
💡 Hint

Divide each number by the total sum and round to two decimals.

visualization
advanced
2:00remaining
Identify the correct pie chart visualization

Which pie chart correctly shows the proportions of categories [25, 25, 50]?

Matplotlib
import matplotlib.pyplot as plt
sizes = [25, 25, 50]
plt.pie(sizes, labels=['A', 'B', 'C'], autopct='%1.1f%%')
plt.show()
AA pie chart with three slices: two equal slices each 25% and one slice 50%.
BA pie chart with three slices: one slice 25%, one slice 50%, and one slice 75%.
CA pie chart with three slices all equal at 33.3%.
DA pie chart with two slices: one 50% and one 50%.
Attempts:
2 left
💡 Hint

Check if the slices add up to 100% and match the data.

🔧 Debug
expert
2:30remaining
Find the error in pie chart proportions calculation

What error does this code produce when trying to plot a pie chart?

import matplotlib.pyplot as plt
sizes = [10, 20, 30]
angles = [x / sum(sizes) * 360 for x in sizes]
plt.pie(angles, labels=['X', 'Y', 'Z'])
plt.show()
AThe pie chart shows incorrect proportions because angles are used instead of raw data.
BSyntaxError due to missing colon in list comprehension.
CTypeError because plt.pie expects integers, but angles are floats.
DRuntimeError because sum(sizes) is zero causing division by zero.
Attempts:
2 left
💡 Hint

Think about what plt.pie expects as input values.