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

I am doing a dozen stories with Gnuplot on Mac through ruby-gnuplot . If I re-run the ruby ​​script, the number of open windows with graphs doubles. If I could just output all these graphs to a PDF opened in Preview, then the file will be automatically updated after each restart, and I don’t have to worry about closing numerous windows.

Currently, I can achieve this with only one plot in a 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 one PDF with all my numbers from Gnuplot?

+6
ruby pdf gnuplot multipage
source share
2 answers

Hmm, at least for gnuplot for UN * x, multi-page output for postscript and PDF has always been the default β€” unless you change the terminal type and reassign the output file, everything you plan ends on a new page.

those. you do:

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

and you will get two pages in a PDF file, one of which contains a line / parabola, the other a sine / cosine.

To clarify: it is important that all plot commands are executed sequentially, without changing the output file or changing the type of terminal. Gnuplot will not be added to an existing PDF file.

+7
source share

I make thousands of ruby-gnuplot stories and use a gem called shrimp to compile them into pdf. Below is a shrimp code snippet 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 

It should be easy enough to adapt to your goals.

0
source share

All Articles