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

2

6

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?

Dulia answered 2/12, 2010 at 11:12 Comment(0)
A
10

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.

Addictive answered 2/12, 2010 at 11:21 Comment(2)
You are right - I was reassigning the output in between the plots. Thanks for opening my eyes!Dulia
I didn't get it. Where to set the terminal/output if using Ruby-Gnuplot?Bowls
A
0

I make thousands of plots with ruby-gnuplot and use a gem called prawn to compile them into a pdf. The following is a code snippet using prawn, that includes some useful features:

require 'prawn'

def create_pdf
  toy_catalogue = @toy_catalogue
  full_output_filename ||= "#{output_path}/#{pre-specified_filename_string}"
  Prawn::Document.generate(full_output_filename, :page_layout => :portrait, :margin => 5, :skip_page_creation => false, :page_size => [595, 1000]) do
    toy_catalogue.each do |toy|
      start_new_page

      image toy[:plan_view], :at => [0,900], :width => 580

      image toy[:front_view], :at => [0, 500], :width => 585

      font_size(20) { draw_text toy[:name], :at => [5, 920] }

      draw_text "production_date = #{toy[:date]}", :at => [420, 930]
    end
  end
end

That should be easy enough to adapt to your purposes.

Alike answered 16/4, 2014 at 23:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.