How to create a multi-page PDF-file with Gnuplot?

Andrei Fokau picture Andrei Fokau · Dec 2, 2010 · Viewed 7.3k times · Source

I make a dozen of plots with Gnuplot on Mac via ruby-gnuplot. If I re-run my ruby script, then the number of open windows with the plots doubles. If I could just output all these plots in a PDF opened in Preview, then the file would be automatically updated after every re-run and I don't need to bother closing the numerous windows.

Currently I can achieve this only with one plot per PDF-file:

Gnuplot.open do |gp|
  Gnuplot::Plot.new(gp) do |plot|
    plot.arbitrary_lines << "set terminal pdf \n set output 'figures.pdf'"
    # ...
  end
end

How can I make a single PDF with all my figures by Gnuplot?

Answer

FrankH. picture FrankH. · Dec 2, 2010

Hmm, at least on gnuplot for UN*x, multipage output for postscript and PDF always was the default - as long as you don't either change the terminal type nor reassign the output file, everything you plot ends up on a new page.

I.e. you do:

set terminal pdf
set output "multipageplot.pdf"
plot x, x*x
plot sin(x), cos(x)
set output ""

and you end up with two pages in the PDF file, one containing line/parabola, the other sine/cosine.

To clarify: The important thing is to issue all the plot commands in sequence, without changing the output file nor changing the terminal type. Gnuplot won't append to an existing PDF file.