admin管理员组

文章数量:1310493

I have created several plots and saved each one separately in its own PDF file using the following line of code:

plt.savefig('/path/Plot1.pdf', format='pdf', bbox_inches='tight', dpi=600)

Now, I need to combine some of these plots—let's say four of them—into a single file arranged in a 2x2 grid, without reducing the resolution of the original plots. Additionally, I need to add a title to this new combined plot. The final result should look something like this:

   Big title
Plot1     Plot2
Plot3     Plot4

How can I do this in python ? I tried using the fitz package but there's something wrong with it, I keep getting this error :

----> 1 from frontend import *
      2 import tools
      3 import os.path as op

ModuleNotFoundError: No module named 'frontend'

I tried following some answers here but it's for merging pages, not merging plots from pdfs. Note that the plots inside the pdfs are not exactly images.. please see how I saved them above.

I have created several plots and saved each one separately in its own PDF file using the following line of code:

plt.savefig('/path/Plot1.pdf', format='pdf', bbox_inches='tight', dpi=600)

Now, I need to combine some of these plots—let's say four of them—into a single file arranged in a 2x2 grid, without reducing the resolution of the original plots. Additionally, I need to add a title to this new combined plot. The final result should look something like this:

   Big title
Plot1     Plot2
Plot3     Plot4

How can I do this in python ? I tried using the fitz package but there's something wrong with it, I keep getting this error :

----> 1 from frontend import *
      2 import tools
      3 import os.path as op

ModuleNotFoundError: No module named 'frontend'

I tried following some answers here but it's for merging pages, not merging plots from pdfs. Note that the plots inside the pdfs are not exactly images.. please see how I saved them above.

Share Improve this question asked Feb 3 at 11:39 Programming NoobProgramming Noob 1,3322 gold badges9 silver badges26 bronze badges 1
  • 2 Do you still have access to the data that was used to generate the original plots? It's much easier to change the way the plots are generated, and generate all of them together in a single pdf, than it is to extract the plots from existing pdf files. – Swier Commented Feb 3 at 13:36
Add a comment  | 

1 Answer 1

Reset to default 0

Follow the following examples retrieved from here

import matplotlib.pyplot as plt
import numpy as np

# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

plt.close('all')

# Four axes, returned as a 2-d array
f, axarr = plt.subplots(2, 2)

axarr[0, 0].plot(x, y)
axarr[0, 0].set_title('Axis [0,0]')

axarr[0, 1].scatter(x, y)
axarr[0, 1].set_title('Axis [0,1]')

axarr[1, 0].plot(x, y ** 2)
axarr[1, 0].set_title('Axis [1,0]')

axarr[1, 1].scatter(x, y ** 2)
axarr[1, 1].set_title('Axis [1,1]')

# Fine-tune figure; hide x ticks for top plots and y ticks for right plots
plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False)
plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False)

本文标签: matplotlibCombine plots from separate pdfs into one in pythonStack Overflow