Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Data Science Basics Creating Reports Test: Charts

Lydia O' Brien
Lydia O' Brien
4,014 Points

I can't figure this out!

Please help, I cannot figure this problem out for the life of me!

pdf.py
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

my_pdf = plt.figures()

1 Answer

Kent Åsvang
Kent Åsvang
18,823 Points

So the thing you have done wrong is that you have imported matplotlib.pyplot and used this to make a new object, instead of using the proper module to create a PDF-object. I'll walk you through it :

First the challenge asks you to create a PDF-object and store it in the variable "my_pdf", to do this you must use the module you have imported from 'matplotlib.backends.backend_pdf', which you have already done on line 2 :

from matplotlib.backends.backend_pdf import PdfPages

Then you need to create a pdf-object using this module and store it in the variable 'my_pdf'. This is were you have used an other module you have imported instead of the one you should be using :

my_pdf = PdfPages()

Finally you are asked to end the PDF Stream, which is done with the "close()" method within the PdfPages-module.

my_pdf.close()

It is a very good practice to learn how to figure out this things by using the documentation. The more you practice the easier it gets. And as your knowledge grows you will remember the ones you use a lot. You can have a look at the documentation and use for the PdfPages-module at "https://matplotlib.org/api/backend_pdf_api.html"

I hope this helped.

Lydia O' Brien
Lydia O' Brien
4,014 Points

Thank you so much! This really helped me find out where I went wrong!