Save multiple plots to pdf

Heads up! You've already completed this tutorial.

Matthias_Ottlinger | 2020-08-07 14:51:08 UTC | #1

Hello Guys,

i am a very beginner. i coded with the matplotlib example out of the book a little programm, where after button click six plots are shown (with matplotlib). i integrated a save button and want to save all six plots to a pdf, but i am stuck. the save button works fine, filePath works fine, but when it should save the file errors occur. outside of pyqt5 i know how to deal with this problem (PdfPages, savefig()...) Maybe some of you can give me an example, so i can add it to my little programm.

Thank you very much for your effords, greeting Mathew


martin | 2020-09-11 20:10:57 UTC | #2

Hi @Matthias_Ottlinger welcome to the forum. Sorry I missed this til now, I just had a baby and have been very distracted!

In case it's still helpful to you, I found that when generating multiple plots into a PDF it's usually easiest to layout the entire page in matplotlib using subplots. You can do this, even if you're showing the plots in separate windows.

PyQt/PySide 1:1 Coaching with Martin Fitzpatrick — Save yourself time and frustration. Get one on one help with your Python GUI projects. Working together with you I'll identify issues and suggest fixes, from bugs and usability to architecture and maintainability.

Book Now 60 mins ($195)

To generate the PDF, create a canvas the size of your page, then add the subplots to this, and use matplotlib .savefig() to write the PDF.

Get your project to market with focused expert help
Martin Fitzpatrick Python Application Launch Support
Find out More

Launch Support for your Python Applications

Comprehensive code reviewBugfixes & improvements • Maintainability advice and architecture improvements • Design and usability assessment • Suggestions and tips to expand your knowledgePackaging and distribution help for Windows, Mac & Linux • Find out more.

When you say it works outside pyqt5, is this using the same Python installation?

Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book


Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

Save multiple plots to pdf was written by Martin Fitzpatrick.

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.