在不使用子图的情况下将多个图形保存在一个pdf页面中 [英] Save multiple figures in one pdf page without using subplots
问题描述
我有很多数字,我想以pdf格式将它们放在同一页上. 目前,我正在使用PDF后端,但每个数字只能将它们写在一页上.
I have a lot of figures and i want to get them on the same page in a pdf. Currently i am using the PDF backend, but it only writes them on one page per figure.
要获得一页上的数字列表,需要进行哪些更改?
What changes are needed to get a list of figures on one page?
由于代码的多种原因,我不想使用子图. 因此,假设无法更改绘图部分. 我只想更改将数字保存到pdf的部分:
I don't want to use subplots because of several reasons of the code. So let's say it is not possible to change the plotting part. I only want to change the part where i save the figures to the pdf:
for i in range(number_of_figures):
fig = figures[i]
pp.savefig(fig)
pp.close()
有人有主意吗?
推荐答案
我过去也遇到过同样的问题,但也无法解决.
I have come to the same issue in the past and wasn't able to solve too.
我的解决方法是将图形保存到磁盘,然后使用其他模块将其加入.
My workaround was to save the figures to disk, then use a different module to join them.
签出以下代码:
from PyPDF2 import PdfFileMerger
files = ['f1.pdf', 'f2.pdf'] # put the full path for the file you wanna join
merger = PdfFileMerger()
for pdf in files:
merger.append(open(pdf, 'rb'))
joined_pdf_path = 'joined_pdf_file.pdf'
with open(joined_pdf_path, 'wb') as fout:
merger.write(fout)
这篇关于在不使用子图的情况下将多个图形保存在一个pdf页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!