{"id":80,"date":"2011-06-08T16:47:00","date_gmt":"2011-06-08T16:47:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=80"},"modified":"2011-06-08T16:47:00","modified_gmt":"2011-06-08T16:47:00","slug":"saving-matplotlib-plots-as-pdf","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=80","title":{"rendered":"Saving matplotlib plots as PDF"},"content":{"rendered":"<p>I recently started using matplotlib together with PyQt, and I love it. It&#8217;s awesome and has many more features compared to PyQWT. However, I needed to save the plots to a PDF file. Here is how you do that:<\/p>\n<pre>import matplotlib.backends.backend_pdf<br \/>...<br \/>   @QtCore.pyqtSlot()<br \/>   def printPlots(self):<br \/>      filename,_ = QtGui.QFileDialog.getSaveFileName(self, \"Save plots as PDF file\", \"\", \"Portable Document File (*.pdf)\")<br \/>      if filename == \"\":<br \/>         return<br \/>      pp = matplotlib.backends.backend_pdf.PdfPages(filename)<br \/>      pp.savefig(self.plotFigure)<br \/>      pp.close()<br \/><\/pre>\n<p>Assuming that your figure is called self.plotFigure. You can connect the above slot to a QAction and map it to some nice menu item or shortcut.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently started using matplotlib together with PyQt, and I love it. It&#8217;s awesome and has many more features compared to PyQWT. However, I needed to save the plots to a PDF file. Here is how you do that: import matplotlib.backends.backend_pdf&#8230; @QtCore.pyqtSlot() def printPlots(self): filename,_ = QtGui.QFileDialog.getSaveFileName(self, &#8220;Save plots as PDF file&#8221;, &#8220;&#8221;, &#8220;Portable Document &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=80\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Saving matplotlib plots as PDF&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,60,15],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/80"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=80"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}