Save multiple figures in one pdf page without using subplots

旧城冷巷雨未停 提交于 2020-05-14 09:42:29

问题


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?

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

Does anybody have an idea?


回答1:


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.

Checkout the following code:

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)


来源:https://stackoverflow.com/questions/59648384/save-multiple-figures-in-one-pdf-page-without-using-subplots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!