Reputation: 225
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?
Upvotes: 6
Views: 8333
Reputation: 756
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.
Upvotes: 0
Reputation: 18227
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.
Upvotes: 10