简体   繁体   English

matplotlib:将2个pdf并排合并

[英]matplotlib: merge 2 pdfs to one side-by-side

I have 2 different pdf plots (generated by matplotlib also) and I'd like to combine them as one side-by-side. 我有2个不同的pdf图(也由matplotlib生成),我想将它们并排组合在一起。 Originally I wanted to generate with 2 subplots 121 and 122 but then was too tricky to adjust many details. 本来我想用2个子图121和122生成的,但后来却很难调整许多细节。 So I generated two independent plots. 因此,我生成了两个独立的图。

Is there any way to import those ready pdfs and just make one out of them? 有什么方法可以导入这些现成的pdf文件,然后只制作其中一个? Because at the end in a latex file which I am using, it is much easier to deal with one figure file rather than two! 因为最后我正在使用的乳胶文件中,处理一个图形文件比处理两个图形文件要容易得多!

Thank you! 谢谢!

如果您使用的是Linux或Mac,则pdfjam程序可以执行此操作。

    pdfjam --nup 2x1 leftFig.pdf rightFig.pdf --outfile combinedFig.pdf

I would save the plots as PNGs and then create a PDF out the PNGs using ReportLab. 我将这些图另存为PNG,然后使用ReportLab在PNG中创建PDF。 For example: 例如:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter

c = canvas.Canvas('report.pdf', pagesize=letter)    

c.drawImage('filename1.png', 0,0)
c.drawImage('filename2.png', 0,100)

c.save() 

http://www.reportlab.com/apis/reportlab/2.4/pdfgen.html http://www.reportlab.com/apis/reportlab/2.4/pdfgen.html

Or if you're set on merging multiple PDFs than that's already been answered here: Merge PDF files or you can merge image directly using PIL see here: How do you merge images into a canvas using PIL/Pillow? 或者,如果您设置的是合并多个PDF,而不是此处已回答的问题: 合并PDF文件,或者可以使用PIL直接合并图像,请参见此处: 如何使用PIL / Pillow将图像合并到画布中? .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM