且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python将多个图形保存到一个PDF文件中

更新时间:2023-12-02 19:07:22

使用 PdfPages 解决您的问题.将您的figure对象传递给savefig方法.

Use PdfPages to solve your problem. Pass your figure object to the savefig method.

例如,如果您打开了一大堆figure对象,并且想要将它们保存到多页PDF中,则可以执行以下操作:

For example, if you have a whole pile of figure objects open and you want to save them into a multi-page PDF, you might do:

import matplotlib.backends.backend_pdf
pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
for fig in xrange(1, figure().number): ## will open an empty extra figure :(
    pdf.savefig( fig )
pdf.close()