How to append a plot to an existing pdf file
You could use recordPlot
to store each plot in a list
, then write them all to a pdf file at the end with replayPlot
. Here's an example:
num.plots <- 5
my.plots <- vector(num.plots, mode='list')
for (i in 1:num.plots) {
plot(i)
my.plots[[i]] <- recordPlot()
}
graphics.off()
pdf('myplots.pdf', onefile=TRUE)
for (my.plot in my.plots) {
replayPlot(my.plot)
}
graphics.off()
append page to existing pdf file using python (and matplotlib?)
You may want to use pyPdf for this.
# Merge two PDFs
from PyPDF2 import PdfFileReader, PdfFileWriter
output = PdfFileWriter()
pdfOne = PdfFileReader(open("path/to/pdf1.pdf", "rb"))
pdfTwo = PdfFileReader(open("path/to/pdf2.pdf", "rb"))
output.addPage(pdfOne.getPage(0))
output.addPage(pdfTwo.getPage(0))
outputStream = open(r"output.pdf", "wb")
output.write(outputStream)
outputStream.close()
example taken from here
Thereby you detach the plotting from the pdf-merging.
append pdf file in R - dev.off()
... and all putting all commands from above together
require(ggplot2)
require(gridExtra)
TopFolder <-"...directory on my drive"
setwd(TopFolder)
pdf(file = file.path(TopFolder,"figures","example.pdf"), onefile=TRUE)
g <- list()
for(i in 1:4){
dat <- data.frame(d1 = c(1:10),
d2 = runif(10))
g[[i]] <- qplot(x = d1, y = d2,
data = dat)
}
grid.arrange(g[[1]],g[[2]],g[[3]],g[[4]])
gg <- list()
# each of this plots will be on a separate page
for(i in 1:6){
dat <- data.frame(d1 = c(1:20),
d2 = runif(20))
# here a print is necessary
print(qplot(x = d1, y = d2,
data = dat))
}
dev.off()
is it possible to append figures to Matplotlib's PdfPages?
Sorry, that's a lame question. We just shouldn't use the with
statement.
fig = plt.figure()
ax = fig_zoom.add_subplot(111)
ax.plot(range(10), range(10), 'b')
# create a PdfPages object
pdf = PdfPages(pdffilepath)
# save plot using savefig() method of pdf object
pdf.savefig(fig)
fig1 = plt.figure()
ax = fig_zoom.add_subplot(111)
ax.plot(range(10), range(2, 12), 'r')
pdf.savefig(fig1)
# remember to close the object to ensure writing multiple plots
pdf.close()
Related Topics
Include Tikz Code in Bookdown Figure Environment
Add Download Buttons in Dt::Renderdatatable
How to Install Dependencies When Using "R Cmd Install" to Install R Packages
Faster Reading of Time Series from Netcdf
R Ggplot2 Plotting Hourly Data
Display an Axis Value in Millions in Ggplot
How to Identify the Distribution of the Given Data Using R
Remove the Last Element of a Vector
How to Access the Data Frame That Has Been Passed to Ggplot()
How to Optimize Read and Write to Subsections of a Matrix in R (Possibly Using Data.Table)
Ggplot2: How to Remove Slash from Geom_Density Legend
How to Get Rows, by Group, of Data Frame with Earliest Timestamp
R Glmnet:"(List) Object Cannot Be Coerced to Type 'Double' "