问题
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