Bird
Raised Fist0
Matplotlibdata~20 mins

Why pie charts show proportions in Matplotlib - Challenge Your Understanding

Choose your learning style10 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.

Practice

(1/5)
1. Why do pie charts show slices of different sizes?
easy
A. Because each slice represents a proportion of the total
B. Because slices are randomly sized
C. Because all slices must be equal
D. Because slices represent unrelated data points

Solution

  1. Step 1: Understand what pie chart slices represent

    Each slice shows a part of the whole data set.
  2. Step 2: Connect slice size to proportion

    The size of each slice matches how big that part is compared to the total.
  3. Final Answer:

    Because each slice represents a proportion of the total -> Option A
  4. Quick Check:

    Slice size = proportion [OK]
Hint: Remember: pie slices show parts of a whole [OK]
Common Mistakes:
  • Thinking slices are random sizes
  • Assuming all slices are equal
  • Believing slices show unrelated data
2. Which matplotlib function is used to create a pie chart?
easy
A. plt.bar()
B. plt.pie()
C. plt.scatter()
D. plt.plot()

Solution

  1. Step 1: Recall matplotlib plotting functions

    Matplotlib has specific functions for different chart types.
  2. Step 2: Identify the pie chart function

    The function plt.pie() is designed to create pie charts.
  3. Final Answer:

    plt.pie() -> Option B
  4. Quick Check:

    Pie chart = plt.pie() [OK]
Hint: Pie chart uses plt.pie() function [OK]
Common Mistakes:
  • Using plt.bar() for pie charts
  • Confusing plt.scatter() with pie charts
  • Trying plt.plot() for pie charts
3. What will the following code output?
import matplotlib.pyplot as plt
sizes = [30, 70]
plt.pie(sizes, labels=['A', 'B'])
plt.show()
medium
A. A line plot connecting points 30 and 70
B. A bar chart with two bars of heights 30 and 70
C. An error because labels are missing
D. A pie chart with two slices sized 30% and 70%

Solution

  1. Step 1: Analyze the plt.pie() call

    The sizes list has two values: 30 and 70, which sum to 100.
  2. Step 2: Understand labels and output

    Labels 'A' and 'B' correspond to slices sized 30% and 70% of the pie.
  3. Final Answer:

    A pie chart with two slices sized 30% and 70% -> Option D
  4. Quick Check:

    Pie slices match sizes list [OK]
Hint: Pie slices match sizes list values [OK]
Common Mistakes:
  • Confusing pie chart with bar chart
  • Expecting error due to labels
  • Thinking it creates a line plot
4. Identify the error in this pie chart code:
import matplotlib.pyplot as plt
sizes = [20, 30, 50]
plt.pie(sizes, labels=['X', 'Y'])
plt.show()
medium
A. The sizes list has invalid values
B. plt.pie() cannot plot more than two slices
C. The labels list length does not match sizes list length
D. plt.show() is missing

Solution

  1. Step 1: Check sizes and labels lengths

    Sizes has 3 values, labels has only 2 labels.
  2. Step 2: Understand matplotlib requirements

    Labels must match the number of slices to label each slice properly.
  3. Final Answer:

    The labels list length does not match sizes list length -> Option C
  4. Quick Check:

    Labels count = sizes count [OK]
Hint: Labels count must equal sizes count [OK]
Common Mistakes:
  • Thinking sizes values are invalid
  • Believing plt.pie() limits slices
  • Forgetting plt.show() is needed
5. You want to show proportions of sales for 4 products using a pie chart. The sales are [100, 200, 300, 400]. How do you ensure the pie chart correctly shows proportions?
hard
A. Pass the sales list directly to plt.pie() and add labels for each product
B. Normalize sales to percentages before passing to plt.pie()
C. Use plt.bar() instead because pie charts need percentages
D. Divide each sales value by 1000 before plotting

Solution

  1. Step 1: Understand how plt.pie() works with data

    Matplotlib automatically calculates proportions from raw values.
  2. Step 2: Confirm labels and data match

    Passing raw sales with matching labels shows correct slice sizes.
  3. Final Answer:

    Pass the sales list directly to plt.pie() and add labels for each product -> Option A
  4. Quick Check:

    Raw values work; no manual normalization needed [OK]
Hint: Pass raw values; matplotlib calculates proportions [OK]
Common Mistakes:
  • Thinking manual percentage calculation is needed
  • Using bar chart instead of pie chart
  • Scaling values unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard