2010-12-02 29 views
6

我通過ruby-gnuplot在Mac上與Gnuplot打了十幾塊地塊。如果我重新運行我的紅寶石腳本,那麼打開窗口的數量就會增加一倍。如果我可以在預覽中打開的PDF中輸出所有這些圖,那麼在每次重新運行後,文件都會自動更新,而且我不必打擾關閉衆多窗口。如何使用Gnuplot創建多頁PDF文件?

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

我怎樣才能讓我的所有數據使用Gnuplot一個單一的PDF:

目前我只能每PDF文件一個陰謀實現這一目標?

回答

7

嗯,至少在gnuplot爲聯合國* x,多頁輸出的postscript和PDF總是默認的 - 只要你不改變終端類型或重新分配輸出文件,你繪製的所有東西都會以一個新的頁面。

I.e.你這樣做:

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

和你結束了在PDF文件中兩個頁面,一個包含線/拋物線,其他的正弦/餘弦值。

澄清:重要的是按順序發出所有的plot命令,而不改變輸出文件或更改終端類型。 Gnuplot不會附加到現有的PDF文件。

+2

你是對的 - 我重新分配輸出在兩個地塊之間。謝謝你打開我的眼睛! – 2010-12-02 14:52:26

0

我用ruby-gnuplot製作了數千個地塊,並使用一個名爲prawn的gem將它們編譯成pdf。下面的代碼片段用蝦,包括一些有用的功能:

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 

這應該是很容易適應你的目的。