[英]Save multiple figures in one pdf page without using subplots
I have a lot of figures and i want to get them on the same page in a pdf.我有很多数字,我想将它们放在 pdf 的同一页面上。 Currently i am using the PDF backend, but it only writes them on one page per figure.目前我正在使用 PDF 后端,但它只将它们写在每个图的一页上。
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:我只想更改将数字保存到 pdf 的部分:
for i in range(number_of_figures):
fig = figures[i]
pp.savefig(fig)
pp.close()
Does anybody have an idea?有人有想法吗?
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.