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
1 Answer
Reset to default 0Follow 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
版权声明:本文标题:matplotlib - Combine plots from separate pdfs into one in python - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741824152a2399542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论