Bird
Raised Fist0
Matplotlibdata~10 mins

Why pie charts show proportions in Matplotlib - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a pie chart showing proportions of fruits.

Matplotlib
import matplotlib.pyplot as plt

sizes = [30, 45, 25]
labels = ['Apples', 'Bananas', 'Cherries']
plt.pie(sizes, labels=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Alabels
Bcolors
Csizes
Dexplode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the sizes list instead of labels for the labels parameter.
Confusing colors or explode parameters with labels.
2fill in blank
medium

Complete the code to add percentages on each pie slice.

Matplotlib
plt.pie(sizes, labels=labels, autopct=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'%s%%'
B'%d%%'
C'%.1f%%'
D'%%.1f'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '%d%%' which shows no decimal places.
Using incorrect format strings that cause errors.
3fill in blank
hard

Fix the error in the code to correctly display the pie chart with a shadow.

Matplotlib
plt.pie(sizes, labels=labels, autopct='%.1f%%', [1]=True)
plt.show()
Drag options to blanks, or click blank then click option'
Ashadow
Bshadows
Cshadowed
Dshow_shadow
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'shadows' or 'shadowed'.
Trying to add shadow with unsupported parameters.
4fill in blank
hard

Fill both blanks to create a pie chart with exploded slices and a start angle.

Matplotlib
explode = ([1], [2], 0)
plt.pie(sizes, labels=labels, explode=explode, startangle=90)
plt.show()
Drag options to blanks, or click blank then click option'
A0.1
B0.2
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using integers like 1 which explode slices too much.
Using negative numbers which cause errors.
5fill in blank
hard

Fill all three blanks to create a pie chart with colors, shadow, and percentage format.

Matplotlib
colors = ['gold', 'yellowgreen', [1]]
plt.pie(sizes, labels=labels, colors=colors, autopct=[2], [3]=True)
plt.show()
Drag options to blanks, or click blank then click option'
A'lightcoral'
B'%.0f%%'
Cshadow
D'blue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid color names or missing quotes.
Wrong format strings for autopct causing errors.
Incorrect parameter name for shadow.

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