Save figures as pdf

In my code, I have lots of figuers and I want them to save as pdf. I did it but all plots saved in one page. How can I save them in some pages?

I currently do that with a for loop and FileIO. Don’t know if it’s the best way. This is how I do it:

using VegaLite
using FileIO

# create empty array that will hold graph names
gpharr = []

# create graphs
graph1 = ... 
push!(gpharr, :graph1)

graph2 = ... 
push!(gpharr, :graph2)

# save graphs
for g in gpharr
    save(File(format"PDF", joinpath("graphs", string(g)*".pdf")), eval(g))
    println(string(g))
end

I find that saving is the most time consuming part.

3 Likes

If your goal is to just put all of the plots in a document and you don’t need the document to be a pdf, then an alternative is html.

The easiest way is to save your plots as either .svg or .png and use the img tag to include all of the plots into the document. The problem is that then if you email someone the document, the you will have to send them all of the images too. I have found two ways to inline the images into the html document.

One is to get the binary representation of the png images of your plots and put that into the img tags.

The other way is to just directly embed the plots into the document with the svg tag.

If you really need a pdf, then one possibility would be to use pgfplots. Basically, you save the plots as .pgf or .tex and use the \include macro in LaTeX to combine the plots into your document. I am happy to provide examples if you like.

One solution is here:

It may matter whether you are using Plots.jl or some other plotting package.

1 Like

Welcome to the Julia community! Julia has quite a few plotting packages, so it would be useful to know which one you are using. Please provide an MWE

1 Like