在Julia中将图形输出重定向到多页PDF

时间:2017-07-10 17:43:44

标签: pdf-generation julia

我想将Julia语言脚本中的所有图形输出重新编写为单个多页PDF文件,类似于R中的内容:

pdf(foo.pdf) 
plot(dummy1) 
plot(dummy2)
... 
plot(dummyn)
dev.off() 

通过

重新定位输出流
writemime(io, "application/pdf", plot) 

适用于单个文件,但它似乎不会附加到现有文件。

请注意,我只想将脚本中的所有数据都放到单个pdf中。我不想通过编织进行广泛的报道。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我通常使用matplotlib的PdfPages后端,我猜这是使用python的一个作弊答案,但无论如何这里都是一个例子。

e.g。

using PyCall, PyPlot
@pyimport matplotlib.backends.backend_pdf as pdf

figures = [] # this array will contain all of the figures
for i in 1:2
    f = figure(figsize=(11.69,8.27)) # A4 figure
    ax = subplot(111)
    ax[:plot](rand(5,100)) # random plot
    push!(figures,f) # add figure to figures array
end

pdffile = pdf.PdfPages("fig.pdf") # create pdf file
[pdffile[:savefig](f) for f in figures] # add figures to file
pdffile[:close]() # close pdf file