FAQ: Recreate graphs using Matplotlib! - Labeled Pie Chart

This community-built FAQ covers the “Labeled Pie Chart” exercise from the lesson “Recreate graphs using Matplotlib!”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

Data Visualization in Python

FAQs on the exercise Labeled Pie Chart

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

For this one I kept getting an error when I defined the labels in a plt.legend() method instead of the plt.pie() one. Strangely, it kept complaining about my autopct definition, which I left untouched.

Is this an error with the validation of the response or is it actually wrong to define the labels with plt.legend() after we added the pie charts?

1 Like

I tried it, and it appears differently (as follows) than the expected result.
pie_legend
Though this is not the expected result for this exercise, I think that this way is also appropriate depending on a purpose, so I don’t think it is wrong.

Perhaps the reason for the message about autopct is that the Codecademy system has determined that another task (“put a percentage label on each slice”) has not yet been done.

Stuck on #4 and I don;t know what im doing wrong

import codecademylib
from matplotlib import pyplot as plt

unit_topics = ['Limits', 'Derivatives', 'Integrals', 'Diff Eq', 'Applications']
num_hardest_reported = [1, 3, 10, 15, 1]

#Make your plot here
plt.figure(figsize=(10,8))
plt.pie(num_hardest_reported, autopct='%1d%%')
plt.axis('equal')
plt.legend(unit_topics)
plt.show()

The expected solution is one that specifies the labels parameter in plt.pie (rather than using plt.legend).

plt.pie(num_hardest_reported, labels=unit_topics, autopct='%d%%')

i see, thanks for the clarification