combine multiple pdf plots into one file
You can use sweave/knitr
to get more flexibility and merge easily new plots ,old ones and texts:
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
this my plot 1: % write some texts here
\includepdf{1.pdf}
this my plot 2:
\includepdf{2.pdf}
this my plot 3:
\includepdf{3.pdf}
this my plot 4:
\includepdf{4.pdf}
a new plot:
<<echo=FALSE>>= % chunk for new plots
x <- rnorm(100)
hist(x)
@
\end{document}
Merge / convert multiple PDF files into one PDF
I'm sorry, I managed to find the answer myself using google and a bit of luck : )
For those interested;
I installed the pdftk (pdf toolkit) on our debian server, and using the following command I achieved desired output:
pdftk file1.pdf file2.pdf cat output output.pdf
OR
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf ...
This in turn can be piped directly into pdf2ps.
Merge PDF files
Use Pypdf or its successor PyPDF2:
A Pure-Python library built as a PDF toolkit. It is capable of:
- splitting documents page by page,
- merging documents page by page,
(and much more)
Here's a sample program that works with both versions.
#!/usr/bin/env python
import sys
try:
from PyPDF2 import PdfFileReader, PdfFileWriter
except ImportError:
from pyPdf import PdfFileReader, PdfFileWriter
def pdf_cat(input_files, output_stream):
input_streams = []
try:
# First open all the files, then produce the output file, and
# finally close the input files. This is necessary because
# the data isn't read from the input files until the write
# operation. Thanks to
# https://stackoverflow.com/questions/6773631/problem-with-closing-python-pypdf-writing-getting-a-valueerror-i-o-operation/6773733#6773733
for input_file in input_files:
input_streams.append(open(input_file, 'rb'))
writer = PdfFileWriter()
for reader in map(PdfFileReader, input_streams):
for n in range(reader.getNumPages()):
writer.addPage(reader.getPage(n))
writer.write(output_stream)
finally:
for f in input_streams:
f.close()
output_stream.close()
if __name__ == '__main__':
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
pdf_cat(sys.argv[1:], sys.stdout)
Saving multiple combined-swarm-&-box plots into one pdf file
If you would like to save them together in a panel, replace the for-loop with the following:
fig, axs = plt.subplots(len(col_ids), 1)
sns.set(style="darkgrid")
for i in range(len(col_ids)):
sns.boxplot(x='Groups', y=df[col_ids[i]], data=df, ax=axs[i])
sns.swarmplot(x='Groups', y=df[col_ids[i]], data=df, color="grey", ax=axs[i])
plt.show()
After that you should be able to save them to one PDF.
Python saving multiple figures into one PDF file
Use PdfPages
to solve your problem. Pass your figure
object to the savefig
method.
For example, if you have a whole pile of figure
objects open and you want to save them into a multi-page PDF, you might do:
import matplotlib.backends.backend_pdf
pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
for fig in xrange(1, figure().number): ## will open an empty extra figure :(
pdf.savefig( fig )
pdf.close()
Related Topics
Automated Formula Construction
Truncate Decimal to Specified Places
Difference Between Sort(), Rank(), and Order()
Rscript Could Not Find Function
Change the Order of Stacked Fill Columns in Ggplot2
Getsymbols and Using Lapply, Cl, and Merge to Extract Close Prices
Group Rows in Data Frame Based on Time Difference Between Consecutive Rows
Stacking Multiple Columns Using Pivot Longer in R
How to Change Color in Shiny Dashboard
How to Split Data Frame by Column Names in R
Cast String Directly to Idatetime
Loop Through a Series of Qplots
1-Dimensional Matrix Is Changed to a Vector in R
Extract Certain Files from .Zip
Contrast Between Label and Background: Determine If Color Is Light or Dark