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

查看:1145
本文介绍了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天全站免登陆