Say I have multiple images/plots produced by seaborn or matplotlib in a Python Jupyter Notebook. How do I save all of them into one PDF file in one go?
CodePudding user response:
For matplotlib
you can create subplots
inside the same figure
and use plt.savefig
to save as PDF or PNG. Based on this
Check here for sns.subplot
and use savefig
again.
If you want to save figures created in different cells inside your notebook (in seperate PDF pages) try something like this:
fig1= plt.figure(...)
plt.plot(...)
fig2= plt.figure(...)
plt.plot(...)
from matplotlib.backends.backend_pdf import PdfPages
def multiple_figues(filename):
pp = PdfPages(filename)
fig_nums = plt.get_fignums()
figs = [plt.figure(n) for n in fig_nums]
for fig in figs:
fig.savefig(pp, format='pdf')
pp.close()
CodePudding user response:
in notebook : file => Download as => PDF ...
or
you can import your file in google drive, and open it with google colab then : file => print => save it as a pdf.