Bird
Raised Fist0
Matplotlibdata~20 mins

Donut chart variation in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Donut Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of a simple donut chart code
What will be the output of this code snippet that creates a donut chart using matplotlib?
Matplotlib
import matplotlib.pyplot as plt

sizes = [30, 20, 50]
labels = ['A', 'B', 'C']

plt.pie(sizes, labels=labels, wedgeprops=dict(width=0.4))
plt.show()
AA pie chart with three slices labeled A, B, C but no hole in the center
BAn error because wedgeprops is not a valid argument
CA bar chart with three bars labeled A, B, C
DA pie chart with three slices labeled A, B, C and a hole in the center (donut shape)
Attempts:
2 left
💡 Hint
Look at the wedgeprops argument and what width controls in a pie chart.
❓ data_output
intermediate
1:30remaining
Number of wedges in a donut chart
Given this code, how many wedges (slices) will the donut chart display?
Matplotlib
import matplotlib.pyplot as plt

sizes = [10, 15, 25, 50]
labels = ['W', 'X', 'Y', 'Z']

plt.pie(sizes, labels=labels, wedgeprops=dict(width=0.3))
plt.show()
A4
B3
C1
D0
Attempts:
2 left
💡 Hint
Count the number of elements in the sizes list.
❓ visualization
advanced
2:30remaining
Effect of changing width in donut chart
What visual difference will you see if you change the width in wedgeprops from 0.5 to 0.9 in this donut chart code?
Matplotlib
import matplotlib.pyplot as plt

sizes = [40, 30, 30]
labels = ['Red', 'Green', 'Blue']

plt.pie(sizes, labels=labels, wedgeprops=dict(width=0.5))
plt.show()
AThe hole in the center becomes larger, making the donut thinner
BThe chart changes to a normal pie chart with no hole
CThe hole in the center becomes smaller, making the donut thicker
DThe chart disappears because width 0.9 is invalid
Attempts:
2 left
💡 Hint
Width controls the thickness of the donut ring; higher width means thicker ring.
🔧 Debug
advanced
2:00remaining
Identify the error in donut chart code
What error will this code raise when trying to create a donut chart?
Matplotlib
import matplotlib.pyplot as plt

sizes = [25, 25, 25, 25]
labels = ['Q1', 'Q2', 'Q3', 'Q4']

plt.pie(sizes, labels=labels, wedgeprops={'width': 1.2})
plt.show()
AValueError because width cannot be greater than 1
BTypeError because wedgeprops must be a dict with string keys
CNo error, chart displays normally
DSyntaxError due to wrong dictionary syntax
Attempts:
2 left
💡 Hint
Width controls the thickness of the donut ring and must be between 0 and 1.
🚀 Application
expert
3:00remaining
Customize donut chart with exploded slice
Which code snippet correctly creates a donut chart with the second slice exploded outward?
Aplt.pie([20, 30, 50], labels=['X', 'Y', 'Z'], wedgeprops=dict(width=0.4), explode=[0.1, 0, 0])
Bplt.pie([20, 30, 50], labels=['X', 'Y', 'Z'], wedgeprops=dict(width=0.4), explode=[0, 0.1, 0])
Cplt.pie([20, 30, 50], labels=['X', 'Y', 'Z'], wedgeprops=dict(width=0.4), explode=[0, 0, 0.1])
Dplt.pie([20, 30, 50], labels=['X', 'Y', 'Z'], wedgeprops=dict(width=0.4), explode=[0.1, 0.1, 0])
Attempts:
2 left
💡 Hint
The explode list controls how far each slice is offset; the second slice is index 1.

Practice

(1/5)
1.

What is the main difference between a donut chart and a pie chart in matplotlib?

easy
A. A donut chart has a hole in the center, a pie chart does not.
B. A donut chart uses bars, a pie chart uses slices.
C. A donut chart shows data over time, a pie chart shows categories.
D. A donut chart is 3D, a pie chart is 2D.

Solution

  1. Step 1: Understand pie chart basics

    A pie chart divides a circle into slices representing parts of a whole.
  2. Step 2: Identify donut chart feature

    A donut chart is a pie chart with a hole in the center, making it look like a donut.
  3. Final Answer:

    A donut chart has a hole in the center, a pie chart does not. -> Option A
  4. Quick Check:

    Donut chart = pie chart + hole [OK]
Hint: Donut chart = pie chart with center hole [OK]
Common Mistakes:
  • Thinking donut charts use bars
  • Confusing donut charts with 3D charts
  • Believing donut charts show time series
2.

Which matplotlib code snippet correctly creates a donut chart with a hole size controlled by wedgeprops?

import matplotlib.pyplot as plt
sizes = [30, 40, 30]
plt.pie(sizes, wedgeprops=???)
plt.show()
easy
A. wedgeprops={'height': 0.5}
B. wedgeprops={'radius': 0.5}
C. wedgeprops={'width': 0.5}
D. wedgeprops={'size': 0.5}

Solution

  1. Step 1: Recall donut hole control

    The hole size in a donut chart is set by the 'width' key inside wedgeprops.
  2. Step 2: Match correct syntax

    Using wedgeprops={'width': 0.5} creates a hole half the radius size.
  3. Final Answer:

    wedgeprops={'width': 0.5} -> Option C
  4. Quick Check:

    wedgeprops width controls hole size [OK]
Hint: Use wedgeprops={'width': value} for donut hole [OK]
Common Mistakes:
  • Using 'radius' instead of 'width'
  • Using 'height' or 'size' keys incorrectly
  • Omitting wedgeprops entirely
3.

What will be the visual output of this code?

import matplotlib.pyplot as plt
sizes = [10, 20, 30]
plt.pie(sizes, wedgeprops={'width': 0.3})
plt.show()
medium
A. A donut chart with a thin ring shape
B. A pie chart with no hole in the center
C. A donut chart with a very large hole
D. A bar chart instead of a pie chart

Solution

  1. Step 1: Analyze wedgeprops width value

    The width is set to 0.3, meaning the donut hole is 70% of the radius.
  2. Step 2: Visualize the chart shape

    This creates a donut chart with a thin ring shape because the hole is large but not full radius.
  3. Final Answer:

    A donut chart with a thin ring shape -> Option A
  4. Quick Check:

    width=0.3 means thin donut ring [OK]
Hint: Smaller width = thinner donut ring [OK]
Common Mistakes:
  • Thinking width=0.3 means no hole
  • Confusing hole size with radius
  • Expecting a bar chart output
4.

Identify the error in this donut chart code and select the fix:

import matplotlib.pyplot as plt
sizes = [25, 35, 40]
plt.pie(sizes, wedgeprops={'width': '0.5'})
plt.show()
medium
A. Add labels parameter
B. Remove wedgeprops entirely
C. Change 'width' to 'radius'
D. Change '0.5' to 0.5 (string to float)

Solution

  1. Step 1: Check wedgeprops value type

    The width value is given as a string '0.5', but it must be a number (float).
  2. Step 2: Correct the data type

    Changing '0.5' to 0.5 fixes the type error and creates the donut hole properly.
  3. Final Answer:

    Change '0.5' to 0.5 (string to float) -> Option D
  4. Quick Check:

    width must be float, not string [OK]
Hint: Use numbers, not strings, for wedgeprops values [OK]
Common Mistakes:
  • Using string instead of float for width
  • Changing width key incorrectly
  • Ignoring type errors
5.

You want to create a donut chart showing sales distribution with a hole size that leaves 40% thickness for the slices. Which wedgeprops value should you use?

hard
A. wedgeprops={'width': 0.4}
B. wedgeprops={'width': 0.6}
C. wedgeprops={'width': 0.2}
D. wedgeprops={'width': 1.0}

Solution

  1. Step 1: Understand width meaning

    The 'width' value is the thickness of the slices as a fraction of the radius.
  2. Step 2: Calculate width for 40% thickness

    For 40% thickness for the slices, set width=0.6 (leaving a hole size of 40%).
  3. Final Answer:

    wedgeprops={'width': 0.6} -> Option B
  4. Quick Check:

    width=0.6 gives 40% slice thickness [OK]
Hint: Width = slice thickness fraction (1 - hole size) [OK]
Common Mistakes:
  • Confusing width with hole size
  • Using width less than hole thickness
  • Setting width to 1 (no hole)
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