Python 将多个图形保存到一个 PDF 文件中 [英] Python saving multiple figures into one PDF file

查看:46
本文介绍了Python 将多个图形保存到一个 PDF 文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 python 中(对于在 GUI 中创建的图形),我可以使用以下任一方法将图形保存在 .jpg 和 .pdf 下:

In python (for one figure created in a GUI) I was able to save the figure under .jpg and also .pdf by either using:

plt.savefig(filename1 +  '.pdf')

plt.savefig(filename1 +  '.jpg')

使用一个文件,我想以 .pdf 或 .jpg 格式保存多个数字(就像在数学实验室中所做的那样).有人可以帮忙吗?

Using one file I would like to save multiple figures in either .pdf or .jpg (just like its done in math lab). Can anybody please help with this?

推荐答案

使用 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()

这篇关于Python 将多个图形保存到一个 PDF 文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆