-1

Greeting for new year!

I have a question regarding saving multiple plots (generated by different python files) to a single PDF.

I have three python files P1,P2,P2. Each file generates a plot when I call function. F1,F2,F3 are functions of those files.

When I execute below piece of code, I see three plots as expected. I want to combine these plots and save them in one single PDF.

Any suggestions will be helpful.

Thank you.

import P1
import P2
import P3

P1.F1()
P2.F2()
P3.F3()
Dhruv Bhatt
  • 51
  • 1
  • 5
  • plot, i.e. ```matplotlib.pyplot```? – khgb Jan 02 '22 at 09:47
  • 1
    Does this answer your question? [Save multiple plots in a single PDF file](https://stackoverflow.com/questions/11328958/save-multiple-plots-in-a-single-pdf-file) – NassimH Jan 02 '22 at 09:51

1 Answers1

0

you can use python library PIL for this task

pip install Pillow
from PIL import Image

image1 = Image.open(r'C:\Users\Ron\Desktop\Test\image1.png')
image2 = Image.open(r'C:\Users\Ron\Desktop\Test\image2.png')
image3 = Image.open(r'C:\Users\Ron\Desktop\Test\image3.png')
image4 = Image.open(r'C:\Users\Ron\Desktop\Test\image4.png')

im1 = image1.convert('RGB')
im2 = image2.convert('RGB')
im3 = image3.convert('RGB')
im4 = image4.convert('RGB')

imagelist = [im2,im3,im4]

im1.save(r'C:\Users\Ron\Desktop\Test\myImages.pdf',save_all=True, append_images=imagelist)
Usama Aleem
  • 113
  • 7